Incorrect string value: '\xF9' - php

I'm trying to convert a vBulletin forum in phpBB .. In local everything went well with a sample forum, on the server instead I get this error:
code:
SQL ERROR [ mysqli ]
Incorrect string value: '\xF9' for column 'poll_option_text' at row 1
[1366]
Now, from what I read on the web, it is a coding error .. So I'm trying to change the encoding that column but the result does not change .. I always appears the same mistake ..
Am I doing something wrong?
Should I change the encoding to the database or table ..?

Related

PhpStorm Import data from CSV file to MySQL, Cyrillic problem

I have problem with encoding while trying to import data from CSV file to MySQL database in PhpStorm. The CSV file contains Cyrillic symbols. I've read some articles, tried many things, but none of them worked for me.
In my.ini file I changed:
collation_server=utf8_unicode_ci to collation_server=utf8mb4_unicode_ci and
character_set_server=utf8 to character_set_server=utf8mb4
but the result was still the same.
That's my CSV file:
NAME_1,NAME_2,NAME_3
Vladimir,Ivanov,Kaziyski
ИВАН,ПЕТРОВ,ГЕОРГИЕВ
John,Lee,Smith
ПЕТЪР,ЙОРДАНОВ,ПЕТРОВ
In PhpStorm I click right-button on the database which I will import data and then I click:
then I chose the CSV file
and in the Data Preview section everything looks normal, encoding is set to UTF-8
and after that I get this error
Here is the log:
2:1: Data truncation: Incorrect string value: '\xD0\x98\xD0\x92\xD0\x90...' for column `current_db`.`csv_data`.`NAME_1` at row 2
3:1: Data truncation: Incorrect string value: '\xD0\x98\xD0\x92\xD0\x90...' for column `current_db`.`csv_data`.`NAME_1` at row 1
4:1: Data truncation: Incorrect string value: '\xD0\x98\xD0\x92\xD0\x90...' for column `current_db`.`csv_data`.`NAME_1` at row 2
5:1: Data truncation: Incorrect string value: '\xD0\x9F\xD0\x95\xD0\xA2...' for column `current_db`.`csv_data`.`NAME_1` at row 1
I've searched this error and tried almost all solutions, but nothing worked. The problem for sure is Cyrillic. Does anyone with PhpStorm had the same issue and how to fix it?
utf8 vs utf8mb4 does not matter for Cyrillic, only for Emoji and Chinese.
Please provide SHOW CREATE TABLE. I suspect you did not change the CHARACTER SET for the column(s) that will receive the Cyrillic characters.

PostgreSQL: getting error messages from `pg_convert()`

I'm trying to diagnose a problem only found on a production system and I'm trying to improve the error reporting for errors thrown by pg_convert(), but not sure where to go. I tried changing the code in the dev environment to:
$converted_values = pg_convert($cnx, $table, $values);
if ($converted_values === FALSE)
throw new Exception("Failed to insert record: '".pg_last_error($cnx)."' using values: ".var_export($values, true));
But pg_last_error() returned nothing.
Note: I tested the above by trying to insert a null value into a NOT NULL column. In addition to getting no joy from pg_last_error() the log had some "PHP Notice"s in it. The production log didn't have any such notices. Just the empty return value from pg_convert() :(
I'm running PostgreSQL 9.4.6 on Debian 8.3 and PHP 5.6.22.
From what I can tell, trying to get anything done w/pg_convert() is a bust. It's not very reliable in dealing w/different data, and it's inconsistent about putting double quotes around column names. If you're using pg_convert() you'll likely want to convert to prepared statements. What they do is very different, so you might have to make fundamental changes to your code base, but we made the change and it seems to be working for us.
Edit: and one such problem that pg_convert()/pg_query() seemed to be able to roll w/that pg_execute() doesn't, is empty strings assigned to integer columns where NOT NULL isn't set. To fix this (at least for now) I had to:
loop through the array passed to pg_execute()
call pg_meta_data() when I found one w/an empty string
determine if the destination column is an integer (be careful: there are probably a lot of ways in which the type for an integer column can be expressed) then if nulls are allowed at all
overwrite the empty string w/null.
Inserting a NULL into a NOT NULL column will not trigger an error in pg_convert. Errors will result from connection problems, a missing table, or a missing column, or data that cannot be converted from the PHP structure to the type in the database (e.g. a word to a number).

Date Insertion Issue in Oracle Database and Codeigniter

I am having a problem in updating oracle db table with date column . I have tried many solutions but still not working. I can not insert the date into the database using codeigniter active record or normal query.. the column type is Timestamp. here are some solutions I have tried. could u help please.. thank you
$this->db->set('AC_START',"TO_DATE('2014-03-4 2:30','yyyy-mm-dd hh:mm')");
$this->db->set('AC_END',"TO_DATE('2014-05-5 2:34' ,'yyyy-mm-dd hh:mm')");
$this->db->insert('ACTIVITES');
here is error message that I always get
Error Number:
INSERT INTO "LI_PPPA"."ACTIVITES" ("AC_START", "AC_END") VALUES ('TO_DATE('2014-03-4 2:30','yyyy-mm-dd hh:mm')', 'TO_DATE('2014-05-5 2:34' ,'yyyy-mm-dd hh:mm')')
Filename: Directory\program\system\database\DB_driver.php
Line Number: 330
You have to make sure CI doens't escape the values you are passing to the oracle database, because to_date is an oracle function.
Try the following:
$this->db->set('AC_START',"TO_DATE('2014-03-4 2:30','yyyy-mm-dd hh:mm')",FALSE);
$this->db->set('AC_END',"TO_DATE('2014-05-5 2:34' ,'yyyy-mm-dd hh:mm')",FALSE);
$this->db->insert('ACTIVITES');code here
With that last parameter you are telling CodeIgniter to NOT escape this value.
Sonaryr's answer threw an Oracle error for me: ORA-01810
Oracle SQL Developer Statement Output:
Error report:
SQL Error: ORA-01810: format code appears twice
01810. 00000 - "format code appears twice"
*Cause:
*Action:
To Fix Change MM to MI:
$this->db->set('AC_START',"TO_DATE('2015-09-02 16:35' ,'YYYY-MM-DD HH24:MI')",FALSE);
Write Normal Query To Perform Action Against The TO_DATE(); Codegniter Does not have any library functions for to_date() for oracle.

no element found - SQL statement looks good though

Anyone see what is wrong with this line of code? using php/mysql
$sqlInsert="INSERT INTO sched_trades_proposed (id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,proposedRot,proposed_sched_main_id,timeStampedProposal,randomHash) VALUES('','".$originalDate."',".$_SESSION[userid].",$originalRotation,$original_sched_main_id,'".$proposedDate."',$proposedRad,$proposedRotation,$proposed_sched_main_id,UNIX_TIMESTAMP(),'".$randomHash."')";
fire bug says "no element found" in jquery-1.8.2.js (line 7209, col 314) and points to this INSERT statement. I don’t see anything wrong with the insert statement. I realize fire bug isn't server side. I am still trying to solve the error though. If I comment out this line of code I get no error.
the surrounding code is:
$randomHash=sha1(rand(1,1000));
$sqlInsert="INSERT INTO sched_trades_proposed (id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,proposedRot,proposed_sched_main_id,timeStampedProposal,randomHash) VALUES('','".$originalDate."',".$_SESSION[userid].",$originalRotation,$original_sched_main_id,'".$proposedDate."',$proposedRad,$proposedRotation,$proposed_sched_main_id,UNIX_TIMESTAMP(),'".$randomHash."')";
echo '<p>'.$sqlInsert;
$resultInsert=mysql_query($sqlInsert);
when I manually insert the INSERT statement into mySQL it gives no errors...But I am getting while trying through the web page?
Here is an example with data in the outputted INSERT statement which all looks good:
INSERT INTO sched_trades_proposed (id,originalDate,originalUserid,originalRot,original_sched_main_id,proposedDate,proposedUserid,proposedRot,proposed_sched_main_id,timeStampedProposal,randomHash) VALUES('','2013-01-10',10,7,710,'2013-01-14',3,19,723,UNIX_TIMESTAMP(),'f33f7ae89c2c6ab8e29a3cb0a97bb1f9456aacba')
FYI: the original id is auto incremented, so I insert a '' as the first column which is kosher.
Firebug says so because you echoed it to the client, and the client HTML parsing is confused because of that. Perhaps because that echo got into a wrong place? Remove that echo. Why do you need it? Or place that echo at a place which would not interfere with your HTML code. e.g. perhaps wrap a div/span around where that echo is?
The INSERT returns no data or acknowledgement by itself. If you are using jQuery to display the inserted data, you will need to run another SELECT to get it again. You can also just return the primary key of the inserted row(assuming MySql for the link although the same thing works with PDO). See this

How to display 'text' data correctly with Microsoft ODBC driver for Linux? Currently displaying as random characters

I am trying to display the contents of a field in a MS SQL database, the data type of which is 'text'. When I connect to the database with MS Excel on a PC the value looks something like:
Shipped on the: 18/10/12 Toll IPEC Connote Number: XXX XXX XXXX
When I connect to the database with PHP using the Microsoft ODBC driver for Linux, the output of the text field will display random characters, which are slightly different each time I run the exact same script. Here is what it output the last four times:
Xisep)!ØwXment.class.php))
5isep)!ment.class.php))
µ}isep)!Ø}ment.class.php))
t)!!Owner_IDt)Ø©Ø8
Not sure where it's getting the 'ment.class.php' bit from. That looks like the end of the name of one of my classes, but not one that is included in this particular script. Is the driver broken or what? All other data types (int, varchar, datetime etc) seem to display correctly, the problem only seems to happen with this one text field.
Here is the code:
<?php
require('ConnectWise.inc.php');
$config = new CW_Config;
// Connect to database
$dbcnx = odbc_connect("ConnectWise", $config->db_username, $config->db_password);
// Query database
$query = "select * from Billing_Log where Invoice_Number = '24011'";
$result = odbc_exec($dbcnx, $query);
while ($row = odbc_fetch_array($result)) {
echo $row['Top_Comment'] . "\n";
}
odbc_close($dbcnx);
Here is the output of my last few attempts:
\3ȶä!!¶äY!
öÈö§!!ö§Y!
&Èö×!!ö×Y!
Looks like you're getting an overflow. For some reason SQL is passing the length of your text field as 0, which to SQL means "long" but to PHP means "I dont know" and so PHP is showing whatever is in its memory at the location its expecting data (or something like that - any PHP experts care to explain?).
I've seen this with varchar(max) before but not text. (Converting to) Text is normally the way to fix it. So maybe I'm wrong.
Hope this is of some help. Im not a PHP developer, I just have to use it occasionally, and this sounds much like a painful experience I've gone through before :)

Categories