Posted By

ginoplusio on 11/11/08


Tagged

mysql db executescalar


Versions (?)

execute scalar for php


 / Published in: PHP
 

URL: http://www.barattalo.it/

retrieve only one value from the query

  1. function execute_scalar($sql,$def="") {
  2. $rs = mysql_query($sql) or die(mysql_error().$sql);
  3. if (mysql_num_rows($rs)) {
  4. $r = mysql_fetch_row($rs);
  5. return $r[0];
  6. }
  7. return $def;
  8. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: the_dev on July 8, 2009

If I'm not mistaken your "mysqlfreeresult($rs);" will never be executed because your "return $r[0];" before calling it. The function will immediately stop and return at that point.

Posted By: ginoplusio on January 19, 2010

right. I've removed it. Thanks.

You need to login to post a comment.