Source for file db_connection.class.php
Documentation is available at db_connection.class.php
// *** Tangra (Application Framework and Tools for PHP)
* Contains DB_Connection class
require_once(TANGRA_MAIN_DIR. 'core/tangra_class.class.php');
* Base class for DB_Connection class family.
* DB_Connection class contains connection to DB and methods to query that DB.
* DB connection itself (resource)
* Attempts to connect to database specified with {@link dsn}
* @param string $dsn Valid DSN
* @return boolean returns true on success, flase otherwise
abstract public function connect();
* Disconnects from the DB
* @param boolean $connected
* Manually marking transaction as failed
abstract public function execute($sql, $ignore_sql_injection_warning = false);
* Selects limited ammount of rows
* Useful for paginating the results.
* @param string $sql SQL statement
* @param integer $num_rows number of rows to select
* @param integer $offset offset to start
abstract public function select_limit($sql, $num_rows, $offset);
* Alias of {@link execute()}
abstract public function query($sql);
* Generates next id from sequence
* For RDBMS that does not support sequences this have to be emulated by DB abstraction layer
* @param string $table_id_is_for name of the sequence
* @param unknown_type $start if sequence is not existing $start will be used as initial value when sequence is automatically created
abstract public function generate_id($sequence_name, $start = 1);
* Returns error message if any
* Here is the place to disconnect nicely from the database
* @param unknown_type $auto
* Executes sql statemnt(s) in transaction
* @param DB_Connection $dbc
foreach($sql as $statement) {
$dbc->execute($statement);
* Returns internal db connection object
* This function should be used only if you REALLY need to use DBAL (ADODB, PDO, etc...) specific calls.
* Checks if $sql looks like SQL injection attempt
* This function will check if there are comments in the $sql and if found will return true.
* Don't overtrust this to keep you safe - allways check and escape data before sending it as SQL statement to the RDBMS.
* Please note that by default queries that use UNION are detected as sql inj attempt. Use $ignore_sql_injection_warning = true or comment this check bellow in the method body
* @return boolean Returns true if $sql is suspicious
if (strpos($sql, ';') !== false) { // multiple queries forbidden
if (strpos($sql, ' --') !== false) {
if (strpos($sql, "\t--") !== false) {
if (strpos($sql, "\n--") !== false) {
if (strpos($sql, ' /*') !== false) {
// If you use UNION you will have to either comment next 3 lines, or execute queries with $ignore_sql_injection_warning flag = true
if (strpos($sql, ' union ') !== false) {
* Removes quoted content from $sql_str
while (strpos($sql_str, "'") !== false) {
while (strpos($sql_str, '"') !== false) {
* Removes quoted with $q from $sql_str
* @param string $q One character ' or "
$start = strpos($sql_str, $q);
$end = strpos($sql_str, $q, $start);
$tmp1 = substr($sql_str, 0, $start);
$tmp2 = substr($sql_str, $end);
$sql_str = substr($sql_str, 0, $start);
|