[support] db_query(INSERT return value

Carl Wiedemann carl.wiedemann at gmail.com
Thu Apr 21 02:13:07 UTC 2011


db_fetch_array() shouldn't be used on an INSERT query. You probably want to
use
http://api.drupal.org/api/drupal/includes--database.mysql-common.inc/function/db_last_insert_id/6instead.

On Wed, Apr 20, 2011 at 6:06 PM, Austin Einter <austin.einter at gmail.com>wrote:

> Hi All
> I have a table *resubmt_skill_ids, *it has two coulmns, skillid (primary
> key) and skillname (unique key).
> I have below code. ,
>
> *  $query_string = "INSERT INTO resubmt_skill_ids (skillname)
> VALUES  ('php'), ('sql')  "  ;
>   $result = db_query($query_string);
>
>   if($result)
>   {
>    while($obj = **db_fetch_array($result))
>    {*
> * *
> *           //DO Other stuff*
>
> With this I get the warning:
> warning: mysqli_fetch_object() expects parameter 1 to be mysqli_result,
> boolean given in
> C:\MyWeb6.20\wamp\www\livejobs1\includes\database.mysqli.inc on line 151.
>
> As per Drupal documentation db_query should return "A database query result
> resource, or FALSE if the query was not executed correctly."
> So if($result) condition turns out to be true, can I guess that there will
> be atleast 1 record in $result.
>
> I found data is written to table, and want to have newly written data (both
> skillname and corresponding skillid), can I extract the data from $result,
> or I need to do one more query to get the newly written data.
>
> Thanks Austin
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110420/8bc82836/attachment.html 


More information about the support mailing list