[support] How can I get the error message from database

Earnie Boyd earnie at users.sourceforge.net
Wed Jan 11 21:56:47 UTC 2012


On Wed, Jan 11, 2012 at 4:13 PM, robert mena <robert.mena at 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


More information about the support mailing list