How to: get the number of rows fetched with a SELECT statement from an Access 97 db through ODBC

From: Date: Mon, 09 Aug 2004 16:16:55 +0000
Subject: How to: get the number of rows fetched with a SELECT statement from an Access 97 db through ODBC
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-14022@lists.php.net to get a copy of this message
Hi, I'm using PEAR with great satisfaction (along with PHP5.0.0), but I ran into a problem : how can I get the number of rows fetched with a SELECT statement from an Access 97 db through ODBC? Here is my code: //issue the query $sql = "SELECT $addresses_table_id,$addresses_table_clientlastname,$addresses_table_clientf irstname,$addresses_table_road,$addresses_table_zipcode,$addresses_table_cit y FROM $addresses_table_name WHERE $addresses_table_clientlastname Like '%$search_criteria%' ORDER BY $addresses_table_clientlastname"; require_once 'winvs_connect.php'; //connect to the WinVS database $q = $db->query($sql); if (DB::iserror($q)) { echo($q->getMessage()); } else { echo "List of the WinVS clients(".$q->numRows()." results found):\n"; //some other code } And it displays: List of the WinVS clients(Object id #3 results found): And below the table with all the results fetched from the db. Here is the content of the winvs_connect.php (but I really don't think that the problem comes from here, since the results are displayed properly): <?php require_once 'DB.php'; // require PEAR::DB classes require_once 'CIC_parameters.php'; // Require CIC global parameters and databases definitions $db_user = $winvs_database_login; $db_pass = $winvs_database_password; $db_host = $winvs_database_host; $db_name = $winvs_database_name; $db_engine = $winvs_database_engine; $datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name; if($debug_sql) { echo $sql; echo '<br /><br />'; } // works!!! $datasource = "odbc://Administrator:878012@localhost/CIC"; /* datasource in in this style: dbengine://username:password@host:port/database */ $db = DB::connect($datasource); // attempt connection // if connection failed show error // don't worry about this for now, we get to it in the errors section if(DB::isError($db)) { die($db->getMessage()); } I hope that I was clear enough ;-) Thank you in advance! Mat-the-guy-who-loves-Access97

« previous php.pear.general (#14022) next »