Class: SQLHelper

Source Location: /CORE/system/classes/core/SQLHelper.php

Class SQLHelper

Class Overview

Class used for handling any SQL Statement, which is meant as DB abstraction layer.

It caches loaded - unprepared - Statments for performance issues.

NOTE: There are two super-global Replacer that are automatically appended.

  • 'CID' will be taken from the environment if you do NOT pass it
  • 'DB_PREFIX' will always be added

Located in /CORE/system/classes/core/SQLHelper.php [line 43]



		
				Author(s):
		
  • Kevin Papst
Information Tags:
Version:  $Id: SQLHelper.php,v 1.12 2009/02/14 13:55:23 kpapst Exp $
Copyright:  Copyright (C) Kevin Papst
License:  GNU Public License

Methods

[ Top ]
Method Summary
SQLHelper   SQLHelper()   Initializes the SQLHelper with the required Database Connection.
void   execute()   Executes the SQL Statement and returns the Result.
array   fetchAll()   Fetch all results for the given statement and replacer values.
DatabaseConnection   getConnection()   Get the DB Connection.
int   getCounter()   Returns the amount of executed SQL statements for the object instance.
DBError   getError()   Returns the error which occured when executing the last statement.
void   get_var()  
int   insert()   Executes the Insert Statement and returns the generated ID.
void   loadAndPrepareStatement()   Simple wrapper for
  1. prepareStatement(loadStatement($name)$values)
.
void   loadStatement()   Loads and returns the Statement. If this statement was loaded before, it will be served directly from the Cache.
void   prepareStatement()   Prepares the given Statement by replacing all found {REPLACER} with the values of the submitted values array.
String   quoteAndEscape()   This function cares about quoting and escaping of all values, that will be used for SQL Queries.
mixed   sql()   Executes a SQL Query from a file prepared with the given values.

[ Top ]
Methods
Constructor SQLHelper  [line 56]

  SQLHelper SQLHelper( DatabaseConnection $dbConnection  )

Initializes the SQLHelper with the required Database Connection.

Parameters:
DatabaseConnection   $dbConnection:  dbConnection the Database Connection to be used


[ Top ]
execute  [line 156]

  void execute( $sql  )

Executes the SQL Statement and returns the Result.

Normaly used for Select, Update, Delete ...

Parameters:
   $sql: 


[ Top ]
fetchAll  [line 186]

  array fetchAll( statement $statement, [values $values = array()], [escape $escape = false], [name $name = null]  )

Fetch all results for the given statement and replacer values.

Parameters:
statement   $statement:  string - the statement to execute
values   $values:  array - with a key-value mapped array of the values to be replaced
escape   $escape:  boolean - whether the values should be replaced or not
name   $name:  string - add a name if you only want to fetch the results of a special column

API Tags:
Return:  the array with all results


[ Top ]
getConnection  [line 174]

  DatabaseConnection getConnection( )

Get the DB Connection.


API Tags:
Return:  the DB Connection that is used


[ Top ]
getCounter  [line 207]

  int getCounter( )

Returns the amount of executed SQL statements for the object instance.


API Tags:
Return:  the amount of executed statements


[ Top ]
getError  [line 216]

  DBError getError( )

Returns the error which occured when executing the last statement.

Depends on the underlying database connection.


API Tags:
Return:  the error object or null


[ Top ]
get_var  [line 143]

  void get_var( $sql, [ $name = null]  )

Parameters:
   $sql: 
   $name: 


[ Top ]
insert  [line 165]

  int insert( $sql  )

Executes the Insert Statement and returns the generated ID.

Parameters:
   $sql: 

API Tags:
Return:  the Database ID


[ Top ]
loadAndPrepareStatement  [line 127]

  void loadAndPrepareStatement( $name, $values  )

Simple wrapper for

  1. prepareStatement(loadStatement($name)$values)
.

Parameters:
   $name: 
   $values: 


[ Top ]
loadStatement  [line 111]

  void loadStatement( $name  )

Loads and returns the Statement. If this statement was loaded before, it will be served directly from the Cache.

Parameters:
   $name: 


[ Top ]
prepareStatement  [line 70]

  void prepareStatement( $statement, [ $values = array()], [ $escape = false]  )

Prepares the given Statement by replacing all found {REPLACER} with the values of the submitted values array.

For example you have the SQL: Select * from {TABLE} where id='{ID}'

You would pass an array like this: array('TABLE' => 'item_1', 'ID' => '-1')

Parameters:
   $statement: 
   $values: 
   $escape: 


[ Top ]
quoteAndEscape  [line 96]

  String quoteAndEscape( mixed $value  )

This function cares about quoting and escaping of all values, that will be used for SQL Queries.

Parameters:
mixed   $value:  value the value to be escaped and quoted

API Tags:
Return:  your prepared value to be used for any SQL Query


[ Top ]
sql  [line 138]

  mixed sql( string $name, array $values  )

Executes a SQL Query from a file prepared with the given values.

Parameters:
string   $name:  the filename to load the sql from
array   $values:  the replacer values

API Tags:
Return:  the sql result


[ Top ]