cm sql version 0.1
Copyright Cnet com @ 2004
This package has been developed to simplify the use of databases.
Currently we only support MySQL but we planned to support another SQL servers (PostgresSQL, Oracle) in mid 2005.
Requirement in your script :
require environment.inc, connection.inc, SQL.inc
environment.inc : This file contained all the necessary variables and the error function when
SQL failed. You absolutely need to personalissed this file for your environment. Change de $db
and $host var to reflect your local setting. Notice : You can make query on more than one
database, the $db var is only here to have a default database to connect to (if you don't pass a
$db argument to the select object). You also need to use the function ob_start(); on all your
script, see http://ca.php.net/manual/en/function.ob-start.php. You also need to flush the
containt of the buffer at the end of each script ob_end_flush() :
http://ca.php.net/manual/en/function.ob-end-flush.php
connection.inc : This file contained the connection function. Copy the connect_example() and
change the information for each connection you need. You need to create a function connection
for every user your need to use to connect to the database. Later we will change completely
the function connection to support more than one type of SQL database, if you upgrade to another
cm_sql version please check the ChangeLog to know any change about this.
SQL.inc : This file is the sql class to make your query.
How it work ?
An example for doing a select, insert, delete or anything else.
$store_res = new select("QUERY TO EXECUTE", "CONNECTION FUNCTION (connect_example())", "The database to connect (default is $GLOBALS['db'])");
An example
$query = "SELECT * FROM test";
$store_res = new select($query, "connect_example()");
You need to put the connection function into double quote and you have to called them exactly what is shown before.
After that you have an array : $store_res->result containing the result of your query.
Bellow is an example to extract the data.
for($i=0; $i<count($store_res->result); $i++)
{
# Each row
for($j=0; $j<count($store_res->result[$i]); $j++)
{
# Each cell
echo $store_res->result[$i][$j];
}
echo "\n<BR>";
}
|