PHP Classes
Icontem

Class: Simple SQL


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Paul Williamson  >  Simple SQL  >  Download  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: Simple SQL Support forum
Base name: simplesql-class-php
Description: MySQL wrapper to shortcut common tasks execution
Version: -
Required PHP version: -
License: GNU General Public License (GPL)
All time users: 1640 users
All time rank: 1662
Week users: 2 users
Week rank: 2907
 
  Author   Group folder image Groups   Detailed description  
  Rate classes User ratings   Applications   Files Files  

Author

Picture of Paul Williamson
Name: Paul Williamson <e-mail contact>
Published packages: 2 Browse this author's classes Browse this author's classes
Country: United States United States - PHP jobs in United States
Home page: http://www.protonage.net/
Age: 23
All time rank: 406
Week rank: 1806

Groups

Group folder image Databases Database management, accessing and searching View top rated classes

Detailed description

SYNOPSIS:
This class is meant to shortcut common MySQL database access tasks.

DESCRIPTION:
Simple SQL provides functions to retrieve single fields or rows of a table, insert rows given arrays of column names and values, update single fields of a given table row, delete given table rows and many other common needs.

ADVANTAGES:
- This PHP class file will eliminate nearly all code from the built in std mysql PHP functions.
- Speed, it will dramatically decrease development and execution time.
- Extremely easy to use; one hardly has to understand the MySQL syntax.
- It automatically determines whether or not there is an open connection to the MySQL server. It will connect and reconnect automatically.
- The built in debugging functions make it easy to solve syntax error and logic error.
- Supports arrays for arguments and returns ASSOC arrays from the DB with indexes.
- Stores resource links and common variables such as the last table used.

USE:
Simply include the file at the top of any script you wish to use it on. This class is highly customizeable.

EXAMPLES:


--- Example 1 ----------------------------- (Shows how little line of code is required to simply grab content from a table without using ANY mysql syntax)

<? include('SimpleSQL.class.php');
$db=new SimpleSQL("test_db","localhost","root","");
//Select all rows and coloumns of data from table 'tablename' and put into array
$db->get_content("tablename");
print_r($db->result);
//echo one cell from the result
echo $db->result[4]["active"];


--- Example 2 ----------------------------- (grab one row from a table)

//Get one row from the table "tablename" (note argument for table can be empty because script stores last table used into a public variable)
$db->get_content("","WHERE location='home' AND active='1'");
print_r($db->result);
//echo the `content` (example) from the result
echo $db->result["content"];


--- Example 3 ----------------------------- (shows how to order your results and to limit by 5)

//Get all rows where active is =0, order by id DESC, limit to 5
$db->get_content("","WHERE active='0'","id DESC",5);
print_r($db->result);


--- Example 4 ----------------------------- (shows how simple it is to change the public variables in the script)

//Switch on debugging mode
$db->debug=true;
//Switch on error messaging
$db->errmsgs=true;
//Switch to another DB and change username and password
$db->db_name="AnotherDatabase";
$db->db_username="username";
$db->db_password="password";


--- Example 5 ----------------------------- (insert data into given fields)

//insert data into a database, first list the fields, then the data, use this format: 'filed1','field2','field3'
$db->insert("'field1','field2','field3'","'data for field 1','data for field 2','data for field 3'");
//echo errors if any found
echo $db->error;


--- Example 6 ----------------------------- (update data in any given field)

//Following queries: "UPDATE `new_table` SET `field1`='new data here' WHERE id='34' LIMIT 1;"
$db->update("field1","new value","new_table","WHERE id='34'",1);


--- Example 7 ----------------------------- (delete data)

//Following queries: "DELETE FROM `new_table` WHERE active='0' LIMIT 5;"
//(note: how the following exempts the 2nd argument which is the table name, table names are stored from the last query)
//The third argument is the ORDER BY clause, may be omitted
$db->delete("WHERE active='0'","","",5);


--- Example 8 ----------------------------- (list the number of rows from last query OR new select statment)

//calling the num_rows function will RETURN the integer and not STORE the results into the result public variable
//Following code will return the number of rows from the last SELECT statment, if there was no last SELECT statment then it will return NULL
$num_rows=$db->num_rows();
//Following exemplifies: mysql_num_rows(mysql_query("SELECT * FROM `new_table` WHERE active='1' ORDER BY id DESC LIMIT 4;"))
$num_rows=$db->num_rows("new_table","WHERE active='1'","id DESC", 4);


--- Example 9 ----------------------------- (if there is a need to send your own query then call the private function itself)

//A long complicated query, the resourse is stored in $db->_link and if any errors are stored in $db->error
$db->_query("CREATE TABLE `new_table` ( `id` INT(10) NOT NULL AUTO_INCREMENT, `username` VARCHAR(25) NOT NULL, `password` VARCHAR(255) NOT NULL, `active` TINYINT(1) DEFAULT '0' NOT NULL, PRIMARY KEY (`id`) ) TYPE = MYISAM;");

User ratings

Ratings
Utility
Consistency
Documentation
Examples
Tests
Videos
Overall
Rank
All time:
Good (91.7%)
Good (87.5%)
Sufficient (60.0%)
Sufficient (62.5%)
-
-
Sufficient (66.8%)
300
Month:
Not yet rated by the users

Applications that use this class

Link Description
PrimalWind A very large hosting service for communities
YourFlix A large database to keep track of customers status
Add link image If you know an application of this package, send a message to the author to add a link here.

Files

File Role Description
Accessible without login Plain text file example.php Example examples on how to use this class
Accessible without login Plain text file README.txt Doc. details about this class with 9 discriptive examples
Accessible without login Plain text file simplesql.class.php Class Main file
Accessible without login Plain text file test.php Example A Full test script and setup
Plain text file TODO Doc. Upcomming features
Download all files: simplesql-class-php.tar.gz simplesql-class-php.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products