Class DB

Description

Database specific class - mySQL

Located in /DB.php (line 15)


	
			
Variable Summary
static string $hostname
static boolean|object DB $instance
static string $password
static string $username
integer $affected_row
string $dbname
string $fetch_mode
string $last_query
array|object $last_result
PDO::Statement $last_statement
integer $row_count
Method Summary
static string escape (string $str)
static void prepareDbValues ( &$item, pointer $item)
array buildQuery (string $table, array $where)
vois catch_error ()
void connect ()
void delete ([string $table = NULL], [array/string $where = NULL])
int execute ([string $query = NULL])
void flush ()
integer getLastInsertId ()
string getLastQuesry ()
result getResults ([string $query = NULL])
reulst getRow ([string $query = NULL])
int getRowCount ()
integer insert ([string $table = NULL], [array $data = NULL])
bool internalQuery ([string $query = NULL])
result/affected query ([string $query = NULL])
void selectDB (string $dbname)
void setFetchMode (string $fetch_mode)
void update ([string $table = NULL], [array $data = NULL], [array/string $where = NULL])
Variables
static string $hostname = 'localhost' (line 21)

Host name.

static boolean|object DB $instance = FALSE (line 44)

Represented the DD class instance.

Help to implement the Singleton design pattern.

  • access: private
static string $password = 'root' (line 32)

User password for database.

  • access: private
static string $username = 'root' (line 27)

Database username.

integer $affected_row = NULL (line 75)

Affected row, returned by last query (DML Queryes).

  • access: private
string $dbname = 'lberp' (line 38)

Database name.

string $fetch_mode = PDO::FETCH_OBJ (line 50)

PDO fetch mode.

This variable use we to setting the PDO fetching mode.

  • access: public
string $last_query = NULL (line 55)

Last query, used by this class.

  • access: private
array|object $last_result = NULL (line 65)

Contain the last result.

  • access: private
PDO::Statement $last_statement = NULL (line 60)

After we execute the last query, we obtain a PDO statement.

  • access: private
integer $row_count = NULL (line 70)

Row count, returned by last query.

  • access: private
Methods
static method escape (line 396)

Format a mySQL string correctly for safe mySQL insert (no mater if magic quotes are on or not)

  • access: public
static string escape (string $str)
  • string $str
static method prepareDbValues (line 220)

Helper function, walk the array, and modify the values.

  • access: private
static void prepareDbValues ( &$item, pointer $item)
  • pointer $item
  • &$item
Constructor __construct (line 85)

Constructor.

Implements the Singleton design pattern.

object DB __construct ()
buildQuery (line 313)

Return a result set.

Similar to getResults(), but in this case not need to write a query. The generated query is based on $where associative Array and $table.

Ex.

  1.  $where array();
  2.  $where['username''testUsername';
  3.  $where['id''1';
  4.  $result =  $c->buildQuery('user',$where);
  5.  print_r($result);

  • return: - result set
  • access: public
array buildQuery (string $table, array $where)
  • string $table
  • array $where
catch_error (line 406)

Print the error if exist.

  • access: private
vois catch_error ()
connect (line 98)

Connect to the database and set the error mode to Exception.

void connect ()
delete (line 282)

Delete a record from a table.

Ex. $table = 'tableName'; $where = array('id = 12','AND name = "John"'); OR $where = 'id = 12';

  • access: public
void delete ([string $table = NULL], [array/string $where = NULL])
  • string $table
  • array/string $where
execute (line 176)

Execute a query (INSERT, UPDATE, DELETE).

This function can be used from DB class methids.

  • access: private
int execute ([string $query = NULL])
  • string $query
flush (line 380)

Set to NULL all cached data.

  • access: private
void flush ()
getLastInsertId (line 334)

Return the last insert id.

  • access: public
integer getLastInsertId ()
getLastQuesry (line 344)

Return the last executed query.

  • access: public
string getLastQuesry ()
getResults (line 192)

Return a result set.

  • return: set
  • access: public
result getResults ([string $query = NULL])
  • string $query
getRow (line 206)

Get one row from the DB.

  • return: set
  • access: public
reulst getRow ([string $query = NULL])
  • string $query
getRowCount (line 354)

Returns the number of rows affected by the last SQL statement.

  • access: public
int getRowCount ()
insert (line 232)

Insert a value into a table.

  • access: public
integer insert ([string $table = NULL], [array $data = NULL])
  • string $table
  • array $data
internalQuery (line 156)

Execute a query.

This function can be used from DB class methods.

  • access: private
bool internalQuery ([string $query = NULL])
  • string $query
query (line 125)

Execute a query.

This function can be used from external. The function separate the simple queryes and the INSERT, UPADTE, DELETE queries. Do not use this function without escape the data with function DB::escape

  • return: row depending on query type.
  • access: public
result/affected query ([string $query = NULL])
  • string $query
selectDB (line 110)

Select a database.

  • access: public
void selectDB (string $dbname)
  • string $dbname
setFetchMode (line 370)

Set the PDO fetch mode.

  • access: public
void setFetchMode (string $fetch_mode)
  • string $fetch_mode
update (line 254)

Update a value(s) in a table

Ex: $table = 'tableName'; $data = array('text'=> 'value', 'date'=> '2009-12-01'); $where = array('id=12','AND name="John"'); OR $where = 'id = 12';

  • access: public
void update ([string $table = NULL], [array $data = NULL], [array/string $where = NULL])
  • string $table
  • array $data
  • array/string $where

Documentation generated on Fri, 06 Mar 2009 11:07:37 +0200 by phpDocumentor 1.4.0