How can I get the error message from database
For some reason one of my queries is not executing. I've used the db_error() but I only get 0. I'd like to know how can I get the error message. I am using drupal 6, MySQL. $success = db_query("INSERT INTO {user_profile_fields} (uid, username, id_center, telephone, street, city, distt, country, zip) VALUES ('$uid', '$username', '$idcenter', '$telephone', '$street', '$city', '$district', '$country', '$zip')"); if(!$success) { // here I am using the $error = db_error(); } Regards.
If you use devel.module, you can use db_queryd, which will give you any error messages that are returned by an invalid query. http://api.drupal.org/api/devel/devel.module/function/db_queryd/6 Regards, Todd On 11 Jan 2012, at 16:13, robert mena wrote:
For some reason one of my queries is not executing. I've used the db_error() but I only get 0. I'd like to know how can I get the error message.
I am using drupal 6, MySQL.
$success = db_query("INSERT INTO {user_profile_fields} (uid, username, id_center, telephone, street, city, distt, country, zip) VALUES ('$uid', '$username', '$idcenter', '$telephone', '$street', '$city', '$district', '$country', '$zip')"); if(!$success) { // here I am using the $error = db_error(); }
Regards. -- [ Drupal support list | http://lists.drupal.org/ ]
Also, you should consider using placeholders for the data that you're inserting into {user_profile_fields}. :) db_query("INSERT INTO {user_profile_fields} (uid, username […]) VALUES (%d, '%s')", $uid, $username); Regards, Todd On 11 Jan 2012, at 16:13, robert mena wrote:
For some reason one of my queries is not executing. I've used the db_error() but I only get 0. I'd like to know how can I get the error message.
I am using drupal 6, MySQL.
$success = db_query("INSERT INTO {user_profile_fields} (uid, username, id_center, telephone, street, city, distt, country, zip) VALUES ('$uid', '$username', '$idcenter', '$telephone', '$street', '$city', '$district', '$country', '$zip')"); if(!$success) { // here I am using the $error = db_error(); }
Regards. -- [ Drupal support list | http://lists.drupal.org/ ]
It is quite likely in fact that the lack of placeholders in your query is the reason you're query is failing. One ' in the data for any of those is guaranteed to cause the insert to fail. Depending on where you are getting the data for these fields you may be opening yourself up to SQL injection attacts. Dave -----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Todd Sent: Wednesday, January 11, 2012 1:40 PM To: support@drupal.org Subject: Re: [support] How can I get the error message from database Also, you should consider using placeholders for the data that you're inserting into {user_profile_fields}. :) db_query("INSERT INTO {user_profile_fields} (uid, username [...]) VALUES (%d, '%s')", $uid, $username); Regards, Todd On 11 Jan 2012, at 16:13, robert mena wrote:
For some reason one of my queries is not executing. I've used the db_error() but I only get 0. I'd like to know how can I get the error message.
I am using drupal 6, MySQL.
$success = db_query("INSERT INTO {user_profile_fields} (uid, username, id_center, telephone, street, city, distt, country, zip) VALUES ('$uid', '$username', '$idcenter', '$telephone', '$street', '$city', '$district', '$country', '$zip')"); if(!$success) { // here I am using the $error = db_error(); }
Regards. -- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
On Wed, Jan 11, 2012 at 4:13 PM, robert mena <robert.mena@gmail.com> wrote:
For some reason one of my queries is not executing. I've used the db_error() but I only get 0. I'd like to know how can I get the error message.
I am using drupal 6, MySQL.
$success = db_query("INSERT INTO {user_profile_fields} (uid, username, id_center, telephone, street, city, distt, country, zip) VALUES ('$uid', '$username', '$idcenter', '$telephone', '$street', '$city', '$district', '$country', '$zip')"); if(!$success) { // here I am using the $error = db_error(); }
I've found that the return value isn't dependable to check for errors from db_query. Something more like $error = db_error(); if (!($row = db_fetch_object($success))) { // Do error routine. } Might work for you. -- Earnie -- https://sites.google.com/site/earnieboyd
participants (4)
-
Earnie Boyd -
Metzler, David -
robert mena -
Todd