note 46727 deleted from function.ibase-fetch-object by sean

From: Date: Thu, 21 Oct 2004 15:33:21 +0000
Subject: note 46727 deleted from function.ibase-fetch-object by sean
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78890@lists.php.net to get a copy of this message
Note Submitter: miguelfd at sigmanet dot com dot br ---- 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); } ?> ---- Reason: useless example

« previous php.notes (#78890) next »