SimpleDB
Code simple - solute everything
Mysql driver class for PHP5. Clearly programmed, very easy to use in your application.
Changelog
- new version 0.1.9 avaible (23 Nov 2009)
- new version 0.1.8 avaible (12 Nov 2009)
- repository clear and reset (10 Nov 2009)
- new version 0.1.7 avaible (10 Oct 2009)
Class Methods
- connect, query, fetch to array (MYSQL_ASSOC, MYSQL_NUM and MYSQL_BOTH)
- affected records, query count
- query without resource return
- mysql variables, statistics, last error
- lock, unlock tables
- database optimization
- import mysql dump
- force disconnect and reconnect possibility
- debugging (3 modes!)
Simple example - getting result from MySQL database
This is the most simples example, shows how to get results from database.
require_once('mysql_driver.php'); //include class file
$DB = new DB_MYSQL; //connect to database
$DB->query('SELECT host FROM user'); //send query
$buffer = $DB->fetch()) //fetch result to array - basic method (from last query)
echo $buffer['host']; //where 'host' is a name of desired row in table
But is better to handle variable on query to make sure that you are fetching from right query!
$query1 = $DB->query('SELECT host FROM user'); //send query
$query2 = $DB->query('SELECT password FROM user'); //send query
$query3 = $DB->query('SELECT * FROM help_topic'); //send query :)
$query4 = $DB->query('SELECT user FROM user'); //send query :)
while($buffer = $DB->fetch($query2))
{
echo $buffer['password'].'<br>';
}
Now you are sure, that result will come from:
$query2 = $DB->query('SELECT password FROM user'); //send queryWould you like to know number of affected rows by your query?
No problem :)
echo 'Affected rows: '.$DB->numRows(); //List affected records by last query
Hmm, maybe you want to count queries and and them to your site footer? Here you go:
echo 'Queries: '.$DB->queries; //Number of queries done by script
Simple yes? All functions are simple :)
You are sitting in your admin panel and doing nothing, lets optimize our database!
$DB->optimizeDB(); //database optimization
What?! That`s all? Yes :) You will get result like this:
accounts - Optimized
bans - Optimized
columns_priv - Optimized
db - Optimized
func - Optimized
global_storage - Optimized
guild_invites - Optimized
guild_ranks - Optimized
guilds - Optimized
help_category - Optimized
help_keyword - Optimized
houses - Optimized
...and the rest of tables
I know, you want to see all queries done by the script, and time of executions
First, you will have to enable debug mode:
In mysql_driver.php
private $debug = 2;
Now after some queries and other functions you can paste this:
echo $DB->showSyntaxes();
The output will look like that:
0.0012 sec. SHOW TABLES
0.0909 sec. OPTIMIZE TABLE accounts
0.0151 sec. OPTIMIZE TABLE bans
0.0006 sec. OPTIMIZE TABLE columns_priv
0.0003 sec. OPTIMIZE TABLE db
0.0002 sec. OPTIMIZE TABLE func
0.0116 sec. OPTIMIZE TABLE global_storage
0.0157 sec. OPTIMIZE TABLE house_data
etc...
Fine, now download this class and enjoy.
Any issue?
Leave your feedback here: http://code.google.com/p/simplemysqlclass/issues/list
Already using this class?
Please insert this small button:
in your page footer.
Copy this code:
<a href = 'http://code.google.com/p/simplemysqlclass/' /><img src='http://otsoft.pl/images/buttons/simpledb-class.png'/></a>
Want to join the project?
Want to make a logo of SDB?
Code for SQLite and PostrgeSQL developement?
Mail me: pavlus@otsoft.pl