For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > August 2004 > How to: get the number of rows fetched with a SELECT statement from an Access 97 db t









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to: get the number of rows fetched with a SELECT statement from an Access 97 db t
Mat

2004-08-09, 3:56 pm

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_cli
entlastname,$addresses_table_clientf
irstname,$addresses_table_road,$addresse
s_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




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com