PHP Classes
elePHPant
Icontem

CM SQL: Execute SQL queries and format results

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2004-11-19 (10 years ago) RSS 2.0 feedStarStar 32%Total: 735 All time: 4,242 This week: 1,302Up
Version License Categories  
cm_sql 1.0GNU General Publi...Databases
Description Author  

This is a simple package meant to execute SQL SELECT queries and format the query results.

The select class can connect to the database server, execute SELECT queries and store the results in an array class variable. The database connection can be configured by an external script.

A separate string formatting class can be use format the values returned as query results.

Currently it only supports MySQL but support for other SQL databases, like PostgreSQL and Oracle, is planned for a future release.

Picture of Maurice Courtois
Name: Maurice Courtois <contact>
Classes: 2 packages by
Country: United States United States
Age: 34
All time rank: 63077 in United States United States
Week rank: 1497 Down171 in United States United States Down

Details provided by the author  
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>";
}

  Files folder image Files  
File Role Description
Accessible without login Plain text file AUTHORS Data AUTHORS file
Accessible without login Plain text file CHANGELOG Data CHANGELOG
Accessible without login Plain text file connection.inc Aux. Connection function script
Accessible without login Plain text file environment.inc Conf. Environment variable for the class
Accessible without login Plain text file GPL.txt Lic. License
Accessible without login Plain text file README Doc. Readme
Plain text file SQL.inc Class The SQL class file

 Version Control Unique User Downloads Download Rankings  
 0%Total:735All time:4,242
 This week:0This week:1,302Up
 User Ratings  
 
 All time
Utility:43%StarStarStar
Consistency:43%StarStarStar
Documentation:62%StarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:32%StarStar
Rank:2424