Public Member Functions | Protected Member Functions | Protected Attributes

MysqlEngine Class Reference

MySQL adaptation of DB-Engine. More...

Inheritance diagram for MysqlEngine:
DbEngine

List of all members.

Public Member Functions

 __construct ($server, $user, $pass)
 initialize driver
 __destruct ()
 make sure it shuts down
 beginTransaction ()
 begins a transaction; must be implemented by driver; use sqlBeginTransaction to create the SQL statement!
 commitTransaction ()
 ends a transaction successfully; must be implemented by driver; returns true on success; use sqlCommitTransaction to create the SQL statement!
 deleteRows ($table, $where)
 delete database values; returns the amount of rows deleted or false if an error occurred; use sqlDelete to create the SQL statement!
 escapeBlob ($s)
 escapes blobs; it uses mysqli_escape_string and encloses the value in '' - blobs are binary strings in MySQL
 escapeBool ($b)
 escapes booleans, overwrites the orignal to use "0" and "1" instead of "FALSE" and "TRUE"
 escapeString ($s)
 escapes strings; it uses mysqli_escape_string and encloses the value in ''
 hasTable ($tnm)
 returns whether the table exists; must be implemented by driver
 insert ($table, array $values)
 insert values into a table; returns false on failure, the new primary key if a sequence was set, true otherwise; use sqlInsert to create the SQL statement!
 lastError ()
 returns the error string of the last operation
 rollbackTransaction ()
 ends a transaction with a rollback; must be implemented by driver; returns true on success; use sqlRollbackTransaction to create the SQL statement!
 select ($table, $cols, $where="", $orderby="")
 gets some data from the database; $table is the name of the table, $cols is the list of columns to return or "*" for all, $where is the where clause of the SQL-statement, $orderby may contain additional ORDER BY or GROUP BY clauses; returns array of rows, which are in *_fetch_array format; returns false on error; use sqlSelect to create the SQL statement!; make sure that NULL values are returned as PHP value null (most DB drivers already do this)
 setCharacterSet ($cs, $col="%_bin")
 set the default charset and collation for tables and connections
 setDbName ($dbn)
 set the name of the database to be used
 setPrefix ($pre)
 set a table-name prefix for the database
 setStorageEngine ($e)
 set the name of the storage engine to be used on DB creation
 sqlBeginTransaction ()
 returns the SQL92 statement for beginning a transaction; overwrite this to implement DB specific syntax
 sqlCommitTransaction ()
 returns the SQL92 statement for committing a transaction; overwrite this to implement DB specific syntax
 sqlRollbackTransaction ()
 returns the SQL92 statement for rolling a transaction back; overwrite this to implement DB specific syntax
 tryConnect ()
 connect to the database, must be overwritten by DB driver
 update ($table, array $values, $where)
 update database values; returns how many rows have been changed or false for failure; use sqlUpdate to create the SQL statement!

Protected Member Functions

 columnFlag ($flag, $col, $table)
 returns the correct name/coding of a flag: primarykey, notnull, unique (implies notnull), foreignkey:$table:$col, defaultint:$val, defaultstr:$val, index
 createTable ($tn, $t)
 creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreateTable() etc.
 createTableExtras ($tablename, $table)
 This function can be used to amend the column definitions of a table; if overwritten it must return a string; overwrite this to implement DB specific syntax.
 dataType ($type)
 returns the correct type name for the required abstract data type; types that must be understood are: int32 (INTEGER), int64 (LONG INTEGER), seq32 (auto-incrementing int), seq64, bool (boolean), string:$length (text up to 255 chars, length is optional, default is 255; VARCHAR($length)), text (unlimited text)
 lockDB ($wl)
 locks the database - only used by the backup functions; if necessary should also start a transaction; default just starts a transaction
 sqlCreateTable ($tn, $t)
 creates a SQL92 statement for creating a table; overwrite this to implement DB specific syntax
 tableName ($tn)
 transform an internally used table name to the actual table name in the DB; the default implementation returns exactly what it gets
 unlockDB ()
 unlocks the database - only used by the backup functions; if necessary should also commit a transaction; default just commits

Protected Attributes

 $prefix = ""
 prefix for table names

Detailed Description

MySQL adaptation of DB-Engine.


Constructor & Destructor Documentation

MysqlEngine::__construct ( server,
user,
pass 
)

initialize driver

MysqlEngine::__destruct (  ) 

make sure it shuts down

References rollbackTransaction().


Member Function Documentation

MysqlEngine::beginTransaction (  ) 

begins a transaction; must be implemented by driver; use sqlBeginTransaction to create the SQL statement!

Reimplemented from DbEngine.

References sqlBeginTransaction().

MysqlEngine::columnFlag ( flag,
col,
table 
) [protected]

returns the correct name/coding of a flag: primarykey, notnull, unique (implies notnull), foreignkey:$table:$col, defaultint:$val, defaultstr:$val, index

Reimplemented from DbEngine.

References tableName().

MysqlEngine::commitTransaction (  ) 

ends a transaction successfully; must be implemented by driver; returns true on success; use sqlCommitTransaction to create the SQL statement!

Reimplemented from DbEngine.

References sqlCommitTransaction().

MysqlEngine::createTable ( tablename,
table 
) [protected]

creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreateTable() etc.

to create the actual statement

Reimplemented from DbEngine.

References sqlCreateTable().

MysqlEngine::createTableExtras ( tablename,
table 
) [protected]

This function can be used to amend the column definitions of a table; if overwritten it must return a string; overwrite this to implement DB specific syntax.

Reimplemented from DbEngine.

MysqlEngine::dataType ( type  )  [protected]

returns the correct type name for the required abstract data type; types that must be understood are: int32 (INTEGER), int64 (LONG INTEGER), seq32 (auto-incrementing int), seq64, bool (boolean), string:$length (text up to 255 chars, length is optional, default is 255; VARCHAR($length)), text (unlimited text)

Reimplemented from DbEngine.

MysqlEngine::deleteRows ( table,
where 
)

delete database values; returns the amount of rows deleted or false if an error occurred; use sqlDelete to create the SQL statement!

Reimplemented from DbEngine.

References DbEngine::sqlDelete().

MysqlEngine::escapeBlob ( s  ) 

escapes blobs; it uses mysqli_escape_string and encloses the value in '' - blobs are binary strings in MySQL

Reimplemented from DbEngine.

MysqlEngine::escapeBool ( b  ) 

escapes booleans, overwrites the orignal to use "0" and "1" instead of "FALSE" and "TRUE"

Reimplemented from DbEngine.

MysqlEngine::escapeString ( s  ) 

escapes strings; it uses mysqli_escape_string and encloses the value in ''

Reimplemented from DbEngine.

Referenced by tryConnect().

MysqlEngine::hasTable ( tablename  ) 

returns whether the table exists; must be implemented by driver

Reimplemented from DbEngine.

References $dbScheme, and tableName().

MysqlEngine::insert ( table,
array $  values 
)

insert values into a table; returns false on failure, the new primary key if a sequence was set, true otherwise; use sqlInsert to create the SQL statement!

Reimplemented from DbEngine.

References $dbScheme, and DbEngine::sqlInsert().

MysqlEngine::lastError (  ) 

returns the error string of the last operation

Reimplemented from DbEngine.

MysqlEngine::lockDB ( writelock  )  [protected]

locks the database - only used by the backup functions; if necessary should also start a transaction; default just starts a transaction

Reimplemented from DbEngine.

References $dbScheme, and tableName().

MysqlEngine::rollbackTransaction (  ) 

ends a transaction with a rollback; must be implemented by driver; returns true on success; use sqlRollbackTransaction to create the SQL statement!

Reimplemented from DbEngine.

References sqlRollbackTransaction().

Referenced by __destruct().

MysqlEngine::select ( table,
cols,
where = "",
orderby = "" 
)

gets some data from the database; $table is the name of the table, $cols is the list of columns to return or "*" for all, $where is the where clause of the SQL-statement, $orderby may contain additional ORDER BY or GROUP BY clauses; returns array of rows, which are in *_fetch_array format; returns false on error; use sqlSelect to create the SQL statement!; make sure that NULL values are returned as PHP value null (most DB drivers already do this)

Reimplemented from DbEngine.

References DbEngine::sqlSelect().

MysqlEngine::setCharacterSet ( cs,
col = "%_bin" 
)

set the default charset and collation for tables and connections

Parameters:
cs the character set - like 'latin1' or 'utf8', this must be a charset supported by MySQL, the default is 'utf8'
col the collation to be used, the default is to use the corresponding binary collation (if you specify an empty string the default of MySQL will be used, which is a case independent comparison!)
MysqlEngine::setDbName ( dbn  ) 

set the name of the database to be used

MysqlEngine::setPrefix ( pre  ) 

set a table-name prefix for the database

MysqlEngine::setStorageEngine ( e  ) 

set the name of the storage engine to be used on DB creation

MysqlEngine::sqlBeginTransaction (  ) 

returns the SQL92 statement for beginning a transaction; overwrite this to implement DB specific syntax

Reimplemented from DbEngine.

Referenced by beginTransaction().

MysqlEngine::sqlCommitTransaction (  ) 

returns the SQL92 statement for committing a transaction; overwrite this to implement DB specific syntax

Reimplemented from DbEngine.

Referenced by commitTransaction().

MysqlEngine::sqlCreateTable ( tablename,
table 
) [protected]

creates a SQL92 statement for creating a table; overwrite this to implement DB specific syntax

Reimplemented from DbEngine.

Referenced by createTable().

MysqlEngine::sqlRollbackTransaction (  ) 

returns the SQL92 statement for rolling a transaction back; overwrite this to implement DB specific syntax

Reimplemented from DbEngine.

Referenced by rollbackTransaction().

MysqlEngine::tableName ( tname  )  [protected]

transform an internally used table name to the actual table name in the DB; the default implementation returns exactly what it gets

Reimplemented from DbEngine.

Referenced by columnFlag(), hasTable(), and lockDB().

MysqlEngine::tryConnect (  ) 

connect to the database, must be overwritten by DB driver

Reimplemented from DbEngine.

References escapeString().

MysqlEngine::unlockDB (  )  [protected]

unlocks the database - only used by the backup functions; if necessary should also commit a transaction; default just commits

Reimplemented from DbEngine.

MysqlEngine::update ( table,
array $  values,
where 
)

update database values; returns how many rows have been changed or false for failure; use sqlUpdate to create the SQL statement!

Reimplemented from DbEngine.

References DbEngine::sqlUpdate().


Member Data Documentation

MysqlEngine::$prefix = "" [protected]

prefix for table names


The documentation for this class was generated from the following file: