<?php
require_once("config.php");
// First we get the defines from the config file.
require_once("sql.class.php");
// Now we include the mysql class file.
/********************************************
* *
* *
* Examples on the initialise method *
* *
* *
********************************************/
$sql = new SQL;
/*
Now we initialize the object
The defines from the config file, goes automaticly into the object.
But we could also self put in the object with fx.
The defines should be named like
define('DB_SERVER','SERVER');
define('DB_DATABASE','DATABASE');
define('DB_USER','USER');
define('DB_PASSWORD','PASSWORD');
define('DB_TYPE','MYSQL'); // Could be in future fx. MSSQL or PGSQL
define('DB_PREFIX',''); // Prefix is if the tables have a prefix in front of the tablenames
*/
$sql = new SQL("SERVER","USER_NAME","PASSWORD","DATABASE","MYSQL");
/*
1. argument = The server adress fx. localhost
2. argument = The username to the database
3. argument = the password to the user
4. argument = the database name
5. argument = This isnt in work at this time, but it would basicly could initialise any database, fx MSSQL PGSQL (PostgreSQL)
*/
/********************************************
* *
* *
* Examples on the select methods *
* *
* *
********************************************/
$sql->b_select(array("name","id"),"TABLE","id = 1","id","1,0");
/*
The first is a simple select.
First we have an array with all the fieldnames we could select
Second we have from which table
Third we have a where clausul
Fourth we have an order
Fifth we have a limit
The query would be
SELECT
name, id
FROM
TABLE
WHERE
id = 1
ORDER BY
id
LIMIT
1,0
We could do alot in the select fx.
$sql->b_select("name","table");
SELECT
name
FROM
table
$sql->b_select(array("name","id"),array("table AS t1","table AS t2"),array("id = 1","1 = 1");
SELECT name, id FROM table AS t1, table AS t2 WHERE id = 1 AND 1 = 1
*/
while ($r = $sql->fetch_array()) {
}
/*
Its pretty much just like
while($row = mysql_fetch_array()) {
}
Instead of this, we could do a
*/
$array = $sql->b_fetchobject(array("name","id"),"TABLE","id = 1","id","1,0");
/*
Which is pretty much just like
while($r = $sql->fetch_array()) {
$out[]=array("name"=>$r["name"],"id"=>$r["id"]);
}
And the $out is returned.
*/
$id = $sql->b_getone("id","table");
// Now the $id is returned.
$sql = new SQL;
$sql->showQuery=true;
$sql->b_fetchobject("id","table");
// Now we have set the showQuery to true, and now it will return the array as an error, and the query is shown, but NOT executed
/********************************************
* *
* *
* Examples on the update method *
* *
* *
********************************************/
$sql = new SQL;
$update = array(
"fieldname"=>"value"
);
$sql->b_update($update,"table","id = 1");
/*
This would be a
UPDATE table SET fieldname = value WHERE id = 1
*/
$sql = new SQL;
$update = array("name"=>"Test","email"=>"email@email.to");
$sql->b_update($update,"table","","","",false);
/*
1 argument = The update array
2 argument = table name
3 argument = the where clausul
4 argument = the order clausul
5 argument = the limit clausul
6 argument = Use or do not use the function setQuote... USE THIS ONLY IF YOU ARE 100% SURE ABOUT SQL INJECTIONS!!!!
/********************************************
* *
* *
* Examples on the insert method *
* *
* *
********************************************/
$sql = new SQL;
$insert = array(
"fieldname"=>"value"
);
$sql->b_insert($insert,"table");
/*
This would be
INSERT INTO table (fieldname) VALUES (value)
The array is exactly just as in the update.
*/
$insert = array("name"=>"Test","email"=>"email@email.to");
$sql->b_insert($insert,"table",false);
/*
1 argument = The insert array
2 argument = the table
3 argument = Use or do not use the function setQuote... USE THIS ONLY IF YOU ARE 100% SURE ABOUT SQL INJECTIONS!!!!
/********************************************
* *
* *
* Examples on the delete method *
* *
* *
********************************************/
$sql = new SQL;
$sql->b_delete("table","id = 1","id","1,0");
/*
DELETE FROM table WHERE id = 1 ORDER BY id LIMIT 1,0
1. argument = The table
2. argument = Where clausul
3. argument = Order clausul
4. argument = limit clausul
*/
/*
Now I explained most of the methods in the class,
all the methods are explained with a little comment
above the method in the class file.
*/
?>
|