Sorry I couldn't helpout more, but I had to shutdown my home MYSQL box cause they are blacking out various areas of my city because of the "energy crisis" so I couldn't test any code. But here is an abstraction class that I wrote for MySQL that works just fine.
<?php
////
// This class will create a connection to a database, and perform querys
////
class DBConnection {
var $dbConn; // Internal Database Connection Id
var $database; // Internal database to be used
var $fieldCount; //The count of all fields returned by a query
var $debug = 0; // Display Debugging messages 1=display 0=no display
function DBConnection($db, $username, $password, $host="localhost") {
$this->dbConn = mysql_connect($host, $username, $password);
if (!$this->dbConn) {
$this->reportError($this->dbConn);
return 0;
}
if (!mysql_select_db($db, $this->dbConn)) {
$this->reportError($this->dbConn);
}
else {
$this->database = $db;
}
return $this->dbConn;
}
function doQuery($query, &$data, $type = "SELECT") {
$result = mysql_db_query($this->database, $query, $this->dbConn);
if (!$result) {
$this->reportError($this->dbConn, $query);
return;
}
if ($type != "SELECT") {
return 0;
}
$this->fieldCount = mysql_num_fields($result);
$row_id = 0;
while ($row = mysql_fetch_array($result)) {
$row_id++;
if ($row_id == 1) {
$fields = array();
$fields = $this->fieldNames($result);
}
for ($i = 0; $i < mysql_num_fields($result); $i++) {
$data[$row_id][$fields[$i]] = $row[$i];
}
}
return $row_id;
}
function fieldNames($query_id) {
$field = array();
for ($i = 0; $i < $this->fieldCount; $i++) {
$field[$i] = strtoupper(mysql_field_name($query_id, $i));
}
return $field;
}
function reportError($dbConn, $info="") {
if ($this->debug) {
$msg = mysql_error($dbConn);
$msg .= $info;
print "<font color=\"red\">DataBase Error: $msg</font>";
}
}
}
?>
It's very easy to use.
$db = DBConnection("DATABASE NAME", "USER NAME", "PASSWORD", "HOST (OPTIONAL");
$query = "SELECT firstname, lastname FROM TABLE";
$data = array();
$count = $db->doQuery($query, $data);
At this point the array $data will be 1-based and filled wiht an associative array of field names and there values. So if you have 3 rows in your table $data will be filled like this.
$data[1]["FIRSTNAME"] = John;
$data[1]["LASTNAME"] = Doe;
$data[2]["FIRSTNAME"] = Jane;
$data[2]["LASTNAME"] = Doe;
$data[3]["FIRSTNAME"] = Baby;
$data[3]["LASTNAME"] = Doe;
Note that the column names in your table will be in UPPERCASE in the array that get's populated.
If you wanted to do an insert you just need to add the 3rd parameter "INSERT" to the doQuery call.
$query = "INSERT INTO TABLE VALUES ('another', 'doe')";
$data = array();
$db->doQuery($query, $data, "INSERT");
Unfortunatly you need to pass in the $data array even though it isn't used, it was easier to do that then create 2 separate functions.