I am using db_query to query another datebase outside of my drupal database. This works well, but I have some questions regarding db_query. I cannot seem to find the answers, so if anyone knows, I'd appreciate it!

1 - db_query returns a result object. where is the documentation for the result object? what are the public methods? For example, I would like to be able to find out how many rows are present without having to loop through and count them all.

2 - My database has a unique key that will prevent duplicate insertions into the database by a user. Insertion failures are expected as a matter of course for my application so I want to be able to control the message that the user sees when this situation occurs. Drupal, however, posts a user warning message automatically when this occurs. I do not want the user to see the Drupal generated warnings. How do I stop them? Along these lines, how can I programmatically detect that mysql has returned an error so I can take my desired action?

Thanks!

Comments

exbab’s picture

I suppose I could just bypass db_query and simply use mysql_db_query and the other mysql_ functions as specified here: http://php.net/manual/en/ref.mysql.php directly.

exbab’s picture

i read that a few times ... my questions deal with stuff that was missing from the documentation.

fidot’s picture

You ask what methods are available. Well, in the api (http://api.drupal.org/api/), just enter db_ in the search box on the left and auto-complete will show you all the database methods available.

RE your specific request about number of rows returned, db_num_rows has been removed from D6. The recommended method for D6 is
$countrows = db_result(db_query("SELECT count(*) FROM {my_table}"));

HTH
Terry