DbCon. class.php

Summary
Returns true microtime timestamp
mysql api wrapper class
Fetch data from a table and return as array
Send an sql statement that writes data to a dable (insert, update, delete)
Returns column names in the form of an array for a certain table
returns the contents of the <sql_history> property to the screen in a readable manner
Escape a string
Check if a table exists
Insert multiple rows into the same table in one statement
Sends contents of a file as a query, multiple queries can be seperated by ; within the file

Constants

Fetch Types

FETCH_MULTImultiple rows will be returned from a query sent with the <fetch> method in a multi dimensional array
FETCH_SMARTif multiple rows were returned by mysql then multiple rows will be returned by the <fetch> method in a multi dimensional array, else one row will be returned in a normal array
FETCH_FIELDonly one field of one row will be returned

Functions

microtime_float

function microtime_float()

Returns true microtime timestamp

DbCOn

mysql api wrapper class

Properties

database resource $dbopened database connection
bool $errortrue if an error occured
string $error_queryholds the last query that resulted in an error
bool $l_errortrue if an error occured in a batch of queries
string $dbnameholds the name of the selected database
string $lastsqlholds the most recent sql statement sent
bool $track_sqlif true all sql statements will be stored in an array
array $sql_historyholds all sql statements sent if $track_sql is true
int $timebenchmark
int $query_numholds numbers of queries sent

Load Balancing Properties

This functionality is pretty much all experimental at this point , and further documentation is currently lacking

array $lb_dbsarray that can hold information (db name, host, user password) for multiple database servers
array $lb_table_linksarray allowing you to link certain table names to certain mysql servers in the $lb_dbs array.  If a query is found with a matching table name and load balancing is activated then the database linked to the table name will be used.
variable $lb_last_usedholds the id of the last used database (id being the key that points to the database in the <$lb_dbs> array)
Summary
Fetch data from a table and return as array
Send an sql statement that writes data to a dable (insert, update, delete)
Returns column names in the form of an array for a certain table
returns the contents of the <sql_history> property to the screen in a readable manner
Escape a string
Check if a table exists
Insert multiple rows into the same table in one statement
Sends contents of a file as a query, multiple queries can be seperated by ; within the file

Functions

DbCon

function DbCon($host,  
$dbname,  
$user,  
$pass,  
$permanent = false)

Parameters

string $hosthost address of the mysql server
string $dbnamename of database to select
string $useruser name
string $passuser password
<bool $permanent>if true then the connection to the mysql database will established as a permanent connection

fetch

function fetch($sql,  
$flags =  NULL,
$use_lb =  NULL)

Fetch data from a table and return as array

Parameters

string $sqlSQL statement
<int $flags>flags
<int $use_lb>if set the function will attempt to use a load balancer

Flags

If flags is submitted as FETCH_MULTI then a multidimensional array is returned that holds all the rows returned by the query

If flags is submitted as FETCH_SMART then a multidimensional array is returned if the mysql result contains more than one row, else a normal array is returned that holds the content of this one row

If flags is sub,itted as FETCH_FIELD then only the first field of the first row in the result is returned

If flags is omited then a normal array is returned that holds the contents of the first row in the result

query

function query($sql,  
$use_lb =  NULL)

Send an sql statement that writes data to a dable (insert, update, delete)

Parameters

string $sqlsql statment
<int $use_lb>if set the function will attempt to use load balancing

Returns

intinsert id if statement was an insert statment
resultotherwise query result

get_fields

function get_fields($table,  
$use_lb =  NULL)

Returns column names in the form of an array for a certain table

Parameters

string $tabletable name
<int $use_lb>if set the function will attempt to use load balancing

Returns

arrayarray holding the column names for the specified table
NULLif an error occured

print_history

function print_history()

returns the contents of the <sql_history> property to the screen in a readable manner

esc

function esc($str)

Escape a string

Parameters

string $strstring to escape

Returns

stringthe escaped string

table_exists

function table_exists($table_name,  
$use_lb =  NULL)

Check if a table exists

Parameters

string $table_nametable name

Returns

int1, if the table exists
int0, if the table does not exist

insert_batch

function insert_batch($table,
$col_arr,
$val_arr)

Insert multiple rows into the same table in one statement

Parameters

string $tabletable name
array $col_arrarray holding column names
array $valuesmultidimensional array holding values

col_arr example

$col_arr = array('name', 'age')

values example

$values = array(array('jon',15),array('susan',19))

Returns

arrayarray holding all insert ids
NULLon error

query_file

function query_file($path,  
$find = NULL,
$replace = NULL)

Sends contents of a file as a query, multiple queries can be seperated by ; within the file

Parameters

string $pathfile location
<string $find>if submitted $find will be replaced with $replace before the statement is sent to the mysql server
<string $replace>look $find

Returns

mysql resultresult of the query
function microtime_float()
Returns true microtime timestamp
function DbCon($host,  
$dbname,  
$user,  
$pass,  
$permanent = false)
function fetch($sql,  
$flags =  NULL,
$use_lb =  NULL)
Fetch data from a table and return as array
function query($sql,  
$use_lb =  NULL)
Send an sql statement that writes data to a dable (insert, update, delete)
function get_fields($table,  
$use_lb =  NULL)
Returns column names in the form of an array for a certain table
function print_history()
returns the contents of the sql_history property to the screen in a readable manner
function esc($str)
Escape a string
function table_exists($table_name,  
$use_lb =  NULL)
Check if a table exists
function insert_batch($table,
$col_arr,
$val_arr)
Insert multiple rows into the same table in one statement
function query_file($path,  
$find = NULL,
$replace = NULL)
Sends contents of a file as a query, multiple queries can be seperated by ; within the file
multiple rows will be returned from a query sent with the fetch method in a multi dimensional array
if multiple rows were returned by mysql then multiple rows will be returned by the fetch method in a multi dimensional array, else one row will be returned in a normal array
only one field of one row will be returned