note 46727 added to function.ibase-fetch-object

From: Date: Thu, 21 Oct 2004 13:21:02 +0000
Subject: note 46727 added to function.ibase-fetch-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-78883@lists.php.net to get a copy of this message
This function can return to you the number of a specified field in a specified table. The obrigatory parameter is the name of the table (the first one), the other, like $_where_field and $_where_value you'll only use if you want to get the count like if you was using a WHERE sql clause, and you can declare, as the last parameter, the operator of the where clause, but only if it isn't an "=" operator. The errors returned by this function is passed through the variable $errorno. If its value is 1, it means that you doesn't specified the table; if its value is 2, it means that it coldn't connect; if itsa value is 3, it means that it couldn't query anything; if its value is 4, it means that the query doesn't returned any data and, finally, if its value is 0, it means that no error ocurried. You can get an error by verifying if the $errorno variable isn't 0 (like this "if (!$errorno) { ALL OK!! }"); <? function countData($_table, $_where_field, $_where_value, $_where_op) { if (!$_table) { $errorno = 1; return(0); } elseif (!$_field) { $_field = "*" } if (($_where_field) and ($_where_value)) { $_op = $_where_op?"$_where_op":"="; $_where_exp = "WHERE $_where_field $_op $_where_value"; } if (!$_conn = ibase_connect ("Your data base", "your user name", "your password")) { $errorno = 2; return(0); } $_sql = "SELECT COUNT($_field) AS INT_COUNT FROM $_table $_where_exp"; if (!$_qry = ibase_query ($_conn, $_sql)) { $errorno = 3; return(0); } if (!$_row = ibase_fetch_object ($_qry)) { $errorno = 4; return(0); } $errorno = 0; return($_row->INT_COUNT); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.ibase-fetch-object.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46727 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46727&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46727&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46727&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46727&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46727&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46727&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46727&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78883) next »