note 90807 deleted from function.mysql-query by danbrown
| From: | danbrown@php.net | Date: | Mon, 11 May 2009 13:49:11 +0000 |
| Subject: | note 90807 deleted from function.mysql-query by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154449@lists.php.net to get a copy of this message | ||
Note Submitter: phpfan at smoothwave dot co dot uk
----
Here are a few classes that I have wrote to make accessing the database and retrieving data really
simple. I have three classes that are broken into several notes on this site as they are quite big.
I also have the usage on the last note:
MySQL.php :
<?php
include("MyData.php");
include("MyDB.php");
class MySQL {
private $myDB;
private $rawData;
public function MySQL ($server, $database, $username, $password) {
$this->setDB($server, $database, $username, $password);
}
public function execSQL ($sql, &$results) {
if($this->myDB->openConnection()) {
$this->rawData = $this->myDB->accessDB($sql);
$this->myDB->closeConnection();
$results = $this->compileResults();
}
else {
return(0);
}
return(1);
}
private function compileResults () {
$rowCount = mysql_num_rows($this->rawData);
$fieldCount = mysql_num_fields($this->rawData);
$myData = new MyData();
for($Row=0; $Row<$rowCount; $Row++) {
for($Field=0; $Field<$fieldCount; $Field++) {
$fieldInfo = mysql_fetch_field($this->rawData, $Field);
$fieldName = $fieldInfo->name;
$data = mysql_result($this->rawData, $Row, $fieldName);
$myData->addDataToList($Row, $fieldName, $data);
}
}
return($myData);
}
private function setDB ($server, $database, $username, $password) {
$this->myDB = new MyDB($server, $database, $username, $password);
}
public function getDB () {
return($this->myDB);
}
}
?>