query("SELECT field FROM table"); ^-- change to 1 for debug mode * * if ($mysql->num_rows() > 0) { * while ($mysql->movenext()) { * echo $mysql->getfield("field"); * } * } * * INSERT * include "class.mysql.php"; * $mysql = New mysql('localhost','root','password','database',0); * $mysql->query("INSERT INTO table (field) values ('value')"); * * UPDATE * include "class.mysql.php"; * $mysql = New mysql('localhost','root','password','database',0); * $mysql->query("UPDATE table SET field='newvalue' WHERE fieldID=1"); * * DELETE * include "class.mysql.php"; * $mysql = New mysql('localhost','root','password','database',0); * $mysql->query("DELETE FROM table WHERE fieldID=1"); * * */ /* public: connection parameters */ var $debug; var $host; var $database; var $user; 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 $host * @param $user * @param $password * @param $database */ function mysql ($host,$user,$password,$database,$debug=0) { $this->debug = $debug; if ($this->debug) echo "\n\nDebug On
\n"; $this->host = $host; $this->user = $user; $this->password = $password; $this->database = $database; /** * 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->host
\n"; $this->conn = @mysql_connect($this->host,$this->user,$this->password) or die("#".mysql_errno().":".mysql_error()."
Verbinding met de database mislukt
Het lijkt erop dat er momenteel een storing is bij onze database server. Onze excuses voor het ongemak

Wij zullen er op toezien dat dit zo spoedig mogelijk verholpen wordt."); /** * Select to database */ if ($this->debug) echo "Selecting to $this->database
\n"; @mysql_select_db($this->database,$this->conn) or die("Error:" . mysql_errno() . " : " . mysql_error() . "
\n". debug_backtrace()); 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() . "
$sql
\n"); $this->affectrows($this->conn); 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"; } if(!empty($this->record[$field])){ return($this->record[$field]); } } function affectrows($link) { if ($this->debug) echo "Affected rows: ".mysql_affected_rows($link)."
\n\n"; } function insertid() { $this->insert_id = mysql_insert_id($this->conn); if ($this->debug) echo "Mysql insert ID: ".$this->insert_id."
\n\n"; return $this->insert_id; } } ?>