Link to home
Start Free TrialLog in
Avatar of sasnaktiv
sasnaktivFlag for United States of America

asked on

How to create a $variable from a mysql_error()

Hi Guys,
Is there a way to capture the results of a mysql_error()) into a variable such as $mysql_error = "???";?
I want to state what the error is in my own words.
Thanks,
Sas
mysql_query("UPDATE table SET column1=something") or die(mysql_error() );

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ahmed Merghani
Ahmed Merghani
Flag of Sudan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
First, you should use mysqli instead of mysql extension: mysql extension is deprecated and it will be no more supported.

Secondly, error() function in mysqli (or mysql_error() function in mysql) is useful to debug your script, in order to get the exact error infos. In production server is a security issue to show mysql and php messages to the users and you can safely replace them with another error message:

$error_msg = 'Sorry, this is my error message';
mysql_query("UPDATE table SET column1=something") or die($error_msg);

Open in new window

Avatar of sasnaktiv

ASKER

Thanks, I can work with that code. It gives me the actual error message which allows me to address each error uniquely.
Have a good weekend,
Sas