-----------the class show below:------------
<?php
class DB {
var $host = ""; // the hostname of database server
var $username = "";
var $password = "";
var $Connection_ID = -1;
var $Query_ID = -1;
var $Query_IDList = array(); // An array of executed query
//var $fields = array();
var $Num_of_Rows = -1;
var $Num_of_Fields = -1;
function connect() {
$this->Connection_ID = odbc_connect($this->host, $this->username, $this->password);
/* this part does not support in ODBC
// if(!$this->Connection_ID) {
// $this->Error_Handler("Error in odbc connect");
// }
*/
return $this->Connection_ID;
}
function query($Query_String) {
$this->connect(); // connect to database
$this->Query_ID = odbc_exec($this->Connection_ID, $Query_String);
/* this part does not support in ODBC
// if(!$this->Query_ID) {
// $this->Error_Handler("Invalid String: ".$Query_String);
// }
*/
$this->insertQuery();
return $this->Query_ID;
}
function next_record() {
// return odbc_fetch_into($this->Query_ID, &$this->fields);
return odbc_fetch_row($this->Query_ID);
}
function key($name) {
// return $this->fields[$name];
return odbc_result($this->Query_ID, $name);
}
function num_rows() {
if ($this->Query_ID) {
$this->Num_of_Rows = odbc_num_rows($this->Query_ID);
} else {
$this->Num_of_Rows = 0;
}
return $this->Num_of_Rows;
}
function num_fields() {
if ($this->Query_ID) {
$this->Num_of_Fields = odbc_num_fields($this->Query_ID);
} else {
$this->Num_of_Fields = 0;
}
return $this->Num_of_Fields;
}
function insertQuery() {
$this->Query_IDList[] = $this->Query_ID;
}
function rollback() {
odbc_rollback($this->Connection_ID);
}
function close() {
odbc_free_result($this->Query_ID); // free memory
return odbc_close($this->Connection_ID); // close the connection
}
function Error_Handler($msg) {
echo "$msg\n";
$this->close();
exit();
}
}
class webctDB extends DB {
var $host = "Webct";
var $username = "YourUserName";
var $password = "YourPassWord";
}
?>
-----------------test query-----------------
<?php
include ("./inc/webctDB.inc");
$db = new webctDB();
$query = "SELECT * FROM student";
$db->query($query);
echo $db->num_rows();
$db->close();
I use ODBC to connect MS Access database, then i written the class for connecting database. But any problem in "odbc_num_rows", it only returns -1 in my test query, WHY?? Anyone can help me to solve this problem??