PHP SQL Class
Contact:
For bug reports, feature requests, suggestions, driver submissions please write to djdarkman@root.hu .
Project Goal:
The goal is to provide a simple class for fast , secure and powerfull
database manipulations. This class eases the development of dynamic
database based web applications, by making the code more shorter and
simpler.
Examples:
For proof of concept and demonstrations of usage I provide an example
database and a normal procedural PHP example and an example with this
class.
This is made possible by comparing PHP SQL class`s code with procedural
PHP code, those who just want to learn how to use this class, please
ignore the "classical PHP example"-s.
database:
host: "localhost"
user: "foo"
password: "bar"
database name: "shop"
database type: "MYSQL"
table:`prods`
id |
name |
price |
qty |
3 |
beer |
1 |
100 |
7 |
CD |
0.5 |
0 |
9 |
shoe |
20 |
3 |
1. Connecting to database:
classical PHP example:
$host = "localhost";
$user = "foo";
$password = "bar";
$database = "shop";
$link = mysql_connect($host,$user,$password);
mysql_select_db($database,$link);
PHP SQL Class example:
$Sql = new SQL("MYSQL_DRIVER","localhost","foo","bar","shop");
2. Getting the whole table into one arrary
classical PHP example:
$tmp = array();
$mat = array();
$res = mysql_query("SELECT * FROM `prods`");
while ($tmp = mysql_fetch_array($res,MYSQL_ASSOC))
{
$mat[] = $tmp;
}
PHP SQL Class example:
$mat = $Sql->getQuery("SELECT * FROM `prods`");
3. Getting the number of results
classical PHP example:
$res = mysql_query("SELECT * FROM `prods`");
$count = mysql_num_rows($res);
PHP SQL Class example:
$count= $Sql->countQueryResults("SELECT * FROM `prods`");
More examples are to come.