/ Published in: PHP
Every MySQL class for PHP I've seen so far has been an epic disappointment. This will not lead you to feel the same way. Enjoy!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // manages mysql connection class SQL { private $conn, $lastq; public $query_count = 0; // constructor. connects upon class formation. function SQL ($server, $user, $pw, $db, $persist) { // connect $this->conn = ( // select db return true; } // run a query function query($q) { // run it // increment query count $this->query_count++; // return result return $this->lastq; } // run an unbuffered query. (used only a few times) function query_unbuff($q) { // run it // increment query count $this->query_count++; // return result return $this->lastq; } // free a result function free($r) { } // free last query result function freelast() { } // get result as a numerical array function fetch_row($r = null) { $r = @$r ? $r : $this->lastq; } // get result as a associative array function fetch_assoc($r = null) { $r = @$r ? $r : $this->lastq; } // close mysql connection function close() { } // escape function prot($s) { } // last id function lastid() { } // rows affected by last update/replace/delete/insert function affected_rows() { } // show error message function error_message() { // halt whilst showing the message } // are we connected? function is_connected() { } // return number of results function num($r) { } }