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;");
This package implements several interfaces to provide a DBMS independent access to SQL databases.
The interfaces define functions to manage database conections, execute SQL queries and retrieve results.
There are classes that implement these interfaces for MySQL and Microsoft SQL servers. Applications using these classes may use any of the supported databases eventually without changing the applications code.
The classes handle errors by throwing standard exceptions.
This class is meant to output SQL database query results as HTML tables.
It supports displaying a limited range of query result rows per page with buttons to navigate between multiple pages in case the query returned more rows than the specified limit per page.
This class is tested deeply with MySQL and Microsoft SQL server but it may already support other databases.
It allows the customization of the table column headers, turn values into links to other pages or hide certain columns, have javascript onclick events or merge the content of multiple columns into one.
This package can be used to take backup copies of server files and MySQL databases.
There is one class that can extract the schema and data rows from a given MySQL database and generates a file with SQL statements that can be used to restore the database structure later if necessary. The generate database backup file can be served for download.
There is also another class that traverses a given directory recursively and copies all files and subdirectories to a backup directory.
This class is meant to search in your SQL data values for special characters that may change the meaning of your SQL data and execute actions that may compromise the security of servers.
When some of these suspicious character sequences is found in HTTP POST request values ($_POST), you can:
- Destroy the current session
- Redirect to a new page
- Log the activity
Notice: this class recognise only some of the known types of SQL injection methods and so it is not yet ready to deal with all possible ways to perform this kind of attack.