//------------------------------------------------
class mysql {
//------------------------------------------------
/* public: connection parameters */
var $debug;
var $hostname;
var $databaseName;
var $username;
var $password;
/* private: connection parameters */
var $conn;
var $rstemp;
var $record;
/**
* mysql::mysql()
* Constructor this class - define public connection parameters and
* call the connect method
*
* @param $hostname
* @param $username
* @param $password
* @param $databaseName
*/
function mysql ($debug=0) {
$this->debug = $debug;
if ($this->debug) echo "\n\nDebug On
\n";
$this->hostname = 'localhost';
$this->username = 'root';
$this->password = '';
$this->databaseName = 'crmProject';
/**
/**
* open connection
*/
$this->connect();
}
/**
* mysql::connect()
* Open connection with the server
*
* @return id da conexao
*/
function connect () {
/**
* Open connection
*/
if ($this->debug) echo "Connecting to $this->hostname
\n";
$this->conn = @mysql_connect($this->hostname,$this->username,$this->password)
or die("Connection to $server failed
\n");
/**
* Select to database
*/
if ($this->debug) echo "Selecting to $this->databaseName
\n";
@mysql_select_db($this->databaseName,$this->conn)
or die("Error:" . mysql_errno() . " : " . mysql_error() . "
\n");
return $this->conn;
}
/**
* mysql::query()
* Execute SQL
*
* @param $sql
* @return
*/
function query($sql) {
if ($this->debug) echo "Run SQL: $sql
\n\n";
$this->rstemp = @mysql_query($sql,$this->conn)
or die("Error:" . mysql_errno() . " : " . mysql_error() . "
\n");
return $this->rstemp;
}
/**
* mysql::num_rows()
* return number of records in current select
*
* @param $rstemp
* @return
*/
function num_rows() {
$num = @mysql_num_rows($this->rstemp);
if ($this->debug) echo "$num records returneds
\n\n";
return $num;
}
/**
* mysql::movenext()
* fetch next record in result
*
* @return
*/
function movenext(){
if ($this->debug) echo "Fetching next record ... ";
$this->record = @mysql_fetch_array($this->rstemp);
$status = is_array($this->record);
if ($this->debug && $status) echo "OK
\n\n";
elseif ($this->debug) echo "EOF
\n\n";
return($status);
}
/**
* mysql::getfield()
* get field value from the current record
*
* @param $field
* @return
*/
function getfield($field){
if ($this->debug) {
echo "Getting $field ... ";
//this resource require PHP 4.1 or righter
if (phpversion() >= 4.1) {
if (array_key_exists($field,$this->record)) echo "OK
\n\n";
else echo "Not found
\n\n";
} else echo "
\n\n";
}
return($this->record[$field]);
}
}
?>