Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Fatal error: Uncaught exception 'PDOException'  in PHP script

Posted on 2016-08-15
16
Medium Priority
?
76 Views
Last Modified: 2016-09-09
How do I fix this error?

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\x92s Lim...' for column 'Warranty' at row 1'

I just moved to a new server.  The old server never had script issues.  The new server is throwing errors in my script.  My script updates to row 86 then stops.  I have changed the particular database column to utf8 and utf8mb4_bin and cannot get it to work
0
Comment
Question by:lawrence_dev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 3
  • +2
16 Comments
 
LVL 44

Expert Comment

by:zephyr_hex (Megan)
ID: 41757164
What is the database?

And what is the string that's causing the error?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41757193
You can use try{} catch{} blocks to trap the error.  If you visualize the PDOException, there will be a message value that can give you a better diagnostic message.  Possibly the database is using charset = utf8, when it needs to use utf8mb4.
0
 

Author Comment

by:lawrence_dev
ID: 41757197
Ray,  
I changed the columns with errors collation to utf8mb4 and utf8.   How do I set the entire table to utf8mb4?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:lawrence_dev
ID: 41757219
Disregard, I changed the entire database to utf8mb4 and still received the same error.
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41757345
Incorrect string value: '\x92s Lim...' for column 'Warranty' at row 1'
Are you attempting to include the backslash in the column value? Depending on the database you're working with (which was asked in the first comment but never answered), the backslash is probably the escape character. If you want to include it in the column value, you either need to change the escape character or escape it in the SQL statement. "\x" doesn't translate to any escapable character that I know of, so it is probably generating the error.
0
 

Author Comment

by:lawrence_dev
ID: 41757891
Thanks for your help Kim!  I am using PHP Mysql with PDO.  I have run this same script for over a year with no issues.  My host forced me to move to a new dedicated server/data center and then I started receiving the error.  So I am wondering if it is because of  newer version of PHP or PDO or Mysql??  What is the best way to escape problematic characters like this?

Thanks again!
0
 

Author Comment

by:lawrence_dev
ID: 41757905
Kim, In addition, I am importing the products from a remote csv file...
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41757953
Take a look at the php addslashes function.
0
 
LVL 12

Expert Comment

by:jet-black
ID: 41760079
If you use parameters in your query, you won't face problems with the escaping and this would also be more secure.

PDOStatement::bindParam
0
 

Author Comment

by:lawrence_dev
ID: 41761672
My question is, why cant they just leave stuff well enough alone???  I am contactly changing my working code to please somebody's fetish.  It just does not make sense.

I dont have time to rework the entire page of code.  Please advise the best way to formulate a regex statement to remove the following string:

\xBE  or  \xB5    If I can remove "\x" followed by letters and numbers then I can eliminate most of the errors...

Thanks for your help!!
0
 

Author Comment

by:lawrence_dev
ID: 41761692
$FullDesc = preg_replace("/\x[^a-zA-Z0-9]{2}/", " ", $FullDesc);    

How do I correctly structure this regex?
0
 
LVL 12

Expert Comment

by:jet-black
ID: 41761698
Try this:

$FullDesc = preg_replace('#\\\x[a-z0-9]{2}#i', ' ', $FullDesc);

Open in new window

0
 

Author Comment

by:lawrence_dev
ID: 41761709
jet-black,

Thanks for your help!!

here is my string
$FullDesc = preg_replace('#\\\x[a-zA-Z0-9]{2}#i', ' ', $FullDesc);

Here is the error
 Incorrect string value: '\xB0 swiv...' for column 'Description' at row 1

What is the issue?  I thought I had it addressed above??
0
 

Author Comment

by:lawrence_dev
ID: 41761760
jet-black,

If is "\x" followed by two characters I need it gone.  How do I correctly structure?
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41761895
If is "\x" followed by two characters I need it gone.  How do I correctly structure?
That's a bit vague. A word space is considered a character. As is a period, et al.

Should it be \x followed by any two alpha-numeric characters? jet-black's code has an extra escape character. The first backslash escapes the literal backslash. The third backslash would attempt to escape the x which is not a special character and would probably throw an error. Do you have errors turned on? Try this
$FullDesc = preg_replace('#\\x[a-z0-9]{2}#i', ' ', $FullDesc);

Open in new window

0
 
LVL 12

Accepted Solution

by:
jet-black earned 2000 total points
ID: 41763089
Please write here the result of the following code to find out if there is a matching problem:

echo '<pre>' . $FullDesc . PHP_EOL;
$FullDesc = preg_replace('#\\\x[a-z0-9]{2}#i', ' ', $FullDesc);
echo $FullDesc . PHP_EOL . '</pre>';

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question