Mysql Data too long - php

Context, using doctrine to store an array as longtext in mysql column. Received some Notice: unserialize(): Error at offset 250 of 255 bytes.I therefore did some backtracking to realize the serialized string was truncated because its too big for a long text column. I really doubt that is the case. This string is near and far away from being 4GB.
Someone from this question suggested to take a look at SET max_allowed_packet but mine is 32M.
a:15:{i:0;s:7:"4144965";i:1;s:7:"4144968";i:2;s:7:"4673331";i:3;s:7:"4673539";i:4;s:7:"4673540";i:5;s:7:"4673541";i:6;s:7:"5138026";i:7;s:7:"5140255";i:8;s:7:"5140256";i:9;s:7:"5140257";i:10;s:7:"5140258";i:11;s:7:"5152925";i:12;s:7:"5152926";i:13;s:7:"51
Mysql table collation: utf8_unicode_ci
Any help would be greatly appreciated !!
Full Error
Operation failed: There was an error while applying the SQL script to the database.
ERROR 1406: 1406: Data too long for column 'numLotCommuns' at row 1
SQL Statement:
UPDATE `db`.`table` SET `numLotCommuns`='a:15:{i:0;s:7:\"4144965\";i:1;s:7:\"4144968\";i:2;s:7:\"4673331\";i:3;s:7:\"4673539\";i:4;s:7:\"4673540\";i:5;s:7:\"4673541\";i:6;s:7:\"5138026\";i:7;s:7:\"5140255\";i:8;s:7:\"5140256\";i:9;s:7:\"5140257\";i:10;s:7:\"5140258\";i:11;s:7:\"5152925\";i:12;s:7:\"5152926\";i:13;s:7:\"51}' WHERE `id`='14574'

The column was a tinytext...
Only logical explanation I can understand from this is that whether when I created my table in earlier version of doctrine, the default was tiny text
OR
I remember changing the type of the column within doctrine annotations and maybe the update didn't fully convert the type correctly.
Bottom line, check your types even though you use an orm.

Your column must have been defined as varchar(250).
You need to first convert it to the longtext.

Related

MySQL running in Strict Mode and giving me problems. How to fix this?

I have a CSV I download from the State of Florida so I'm not in control over what's in the file. There are some fields (such as price) that are sometimes null. In my table where I'm importing these values, I marked sold_price as BIGINT, Unsigned, Allow Null and default of Null. However, when I attempt to insert a NULL value (empty cell in the CSV), I get the error:
[PDOException]
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'sold_price' at row 1
I followed the advice in this answer someone posted and that fixes the problem. However, whenever MySQL is restarted, I get the error again and have to redo that query.
Also, I don't think that's the appropriate way to fix the problem, is it? What should I be doing in cases where a field such as sold_price is null and I'm trying to insert it into a table?
I'm running MySQL version 5.6.13.
you can disable the strict mode. In you my.ini-file you'll find something like
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Change that to:
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

Zend_Db_Table insert issue with large content

I've been using Zend Framework for quite a while now, but now I have an issue that's got me puzzled. I have a table (MySQL) with just 2 columns (id and msg). The id field is an auto increment value and the msg field is a longtext type.
The following code should work just fine for inserting a record into the table:
$t = new Zend_Db_Table('table1');
$id = $t->insert(array('msg' => $content));
Whenever $content is just a plain string value like 'blah', it works just fine, like it should.
But the fieldtype is not a longtext type for no reason, the content will be quite large.
So now I try to place about 14kb of data in $content, no exception occurs, the database insert seems to have worked, but only for the first 6kb. The rest of the data is just gone?!
When I try to use to oldfashioned mysql_connect, mysql_query, etc routines, it all works like a charm. So it's really seems to be a Zend framework issue...
Has anybody else experienced this?
Configuration
Zend Framework v1.11.10
Zend_Db_Table is configured with the PDO_MYSQL adapter
MySQL database table two columns; id (autoincrement)
Issue
Attempting to INSERT 14kb of UTF8-encoded HTML into longtext column
Zend_Db_Table truncates the data at 6kb
Tests
mysql_query can INSERT the same data without issue
Zend_Db_Table can SELECT all the data without issue
setting error_reporting(-1) reveals 'no errors, warnings or notices'
mediumblob works fine
Isolating the issue
Change the column to a mediumtext. Does the insert work now?
Have you checked what the query actually looks like? See comment above from namesnik.
How many bytes get written on the failed inserts? Is it consistent?

Should I be able to update a MySQL enum type with a text value?

I'm trying to update the value in a MYSQL enum field from PHP via Doctrine (5.3 and 1.2 respectively).
I get an error when I try and do this:
$q = Doctrine_Query::create()
->update('StMessages')
->set('status','new')
->where('message_id = ?',$msg_id);
I get a sql state error telling me that the column 'new' does not exist. If I enter 3 instead of new (presumably the internal index of the 'new' value), then the query works. In fact it happens in a SQL client too so perhaps this is a quirk of this version of MySQL? Its 5.1.45.
Anyone know if this is how MySQL is supposed to treat enums or if this is more likely a Doctrine issue? I have 'use_native_enum' set to true.
Given a table
create table test (
enumfield enum('a','b','c')
);
you should be able to do
update test set enumfield='a';
which is the whole point of the num field - not having to mess with indexes and whatnot.
What's the exact definition of your enum field?
I think this was actually an issue relating to the quoting of strings when updating the field's values. I'm not sure if Doctrine or I was at fault.

Unknown column in 'field list' error on MySQL Update query

i echoed the query below: (query is safe)
UPDATE otelozellik
SET isim_tr='test',
aciklama_tr='<p>test1</p>',
uyari_tr='test',
tag_tr='test'
WHERE id='1'
Database Error: Unknown column
'aciklama_tr' in 'field list'
I changed the order of columns, the one after isim_tr keeps giving error. When I move isim_tr to the last then the one after id giving the same error. But moving them to the last position is not a solution for me because table will be dynamic to add new columns when necessary. need an absolute solution.
UPDATE: LATEST SCREENSHOT: http://img5.imageshack.us/img5/7215/mysqlerror.jpg
Solved. Solution is answered below. Thanks everyone.
Problem is solved. Thank you a lot everyone for their help.
Right Query for solution is:
UPDATE `holidaycholic`.`otelbilgi` SET `otelbilgi`.`isim_tr`='test2', `otelbilgi`.`aciklama_tr`='<p>test2</p>', `otelbilgi`.`uyari_tr`='test2', `otelbilgi`.`tag_tr`='test2' WHERE `otelbilgi`.`id`=1
No idea why but that worked for me.
'field list' errors are caused when you try to load data into a field that doesn't exist. Double check that you spelled your field names correctly.
Your post says that you need to add "dynamic columns". A properly structured database shouldn't have a need for that sort of thing. However, if you do want to add columns from php, you need to add them to the table before you try to insert data in those fields. You can use the ALTER TABLE statement to do this:
ALTER TABLE table_name
ADD column_name datatype
Just to double-check are all the characters you're using the standard ASCII characters or are you using an unusual character set?
Try inserting data into the table using phpMyAdmin or similar - If it works, copy the code it generates and run it yourself using the mysql client.
Assuming that still works, compare the generated code with the SQL generated by your PHP
Here is the syntax which works for me all time:
"INSERT INTO table(`code`, `description`) VALUES ('".mysql_real_escape_string($code)."', '".mysql_real_escape_string($description)."')";
"table" is a table with an AUTO_INCREMENT index.

Data truncated for column 'budget' at row 1"

I encountered this error when I attempted to insert something into a MySQL table. What's the possible reason? How to solve this problem?
The raw value of "budget" is 800元, when inserted, it became 800, 元 is missing.
This would mean that you are trying to insert data that would overflow the allocated storage for that column.
If your SQL Mode is set to strict, any insertion of data that would not fit, will cause an error and the insert will fail, if the mode is non-strict the insert will succeed with truncation giving a warning. But this should not be use as a workaround for this problem. Instead you need to identify the field which is causing this and should update the table to make it wide enough to accommodate the widest data your application might give MySql

Categories