Skip to content

Latest commit

 

History

History
1007 lines (522 loc) · 20 KB

class.DbCore.md

File metadata and controls

1007 lines (522 loc) · 20 KB

Class DbCore

Contents

Constants

Properties

Methods

Constants

INSERT

const INSERT = 1

Constants used by insert() method

INSERT_IGNORE

const INSERT_IGNORE = 2

REPLACE

const REPLACE = 3

Properties

$_servers

protected array $_servers = array(array('server' => _DB_SERVER_, 'user' => _DB_USER_, 'password' => _DB_PASSWD_, 'database' => _DB_NAME_))

$database

protected string $database

$instance

protected array $instance = array()

$is_cache_enabled

protected boolean $is_cache_enabled

$last_cached

protected string $last_cached

Last cached query

$last_query

protected string $last_query

Store last executed query

$link

protected mixed $link

$password

protected string $password

$result

protected mixed $result

$server

protected string $server

$user

protected string $user

Methods

Affected_Rows

mixed DbCore::Affected_Rows()

Get number of affected rows in previous database operation

Insert_ID

mixed DbCore::Insert_ID()

Get the ID generated from the previous INSERT operation

__construct

mixed DbCore::__construct(string $server, string $user, string $password, string $database, boolean $connect)

Instantiate database connection

Arguments

  • $server string - Server address
  • $user string - User login
  • $password string - User password
  • $database string - Database name
  • $connect boolean - If false, don't connect in constructor (since 1.5.0)

__destruct

mixed DbCore::__destruct()

Close connection to database

_escape

string DbCore::_escape(string $str)

Protect string against SQL injections

Arguments

  • $str string

_numRows

mixed DbCore::_numRows(mixed $result)

Get number of rows in a result

Arguments

  • $result mixed

_query

mixed DbCore::_query(string $sql)

Execute a query and get result resource

Arguments

  • $sql string

autoExecute

mixed DbCore::autoExecute($table, $data, $type, $where, $limit, $use_cache, $use_null)

Arguments

  • $table mixed
  • $data mixed
  • $type mixed
  • $where mixed
  • $limit mixed
  • $use_cache mixed
  • $use_null mixed

autoExecuteWithNullValues

mixed|boolean DbCore::autoExecuteWithNullValues(string $table, string $values, string $type, string $where, integer $limit)

Filter SQL query within a blacklist

Arguments

  • $table string - Table where insert/update data
  • $values string - Data to insert/update
  • $type string - INSERT or UPDATE
  • $where string - WHERE clause, only for UPDATE (optional)
  • $limit integer - LIMIT clause (optional)

checkConnection

integer DbCore::checkConnection(string $server, string $user, string $pwd, string $db, boolean $new_db_link, boolean $engine, $timeout)

Try a connection to te database

Arguments

  • $server string - Server address
  • $user string - Login for database connection
  • $pwd string - Password for database connection
  • $db string - Database name
  • $new_db_link boolean
  • $engine boolean
  • $timeout mixed

checkEncoding

integer DbCore::checkEncoding(string $server, string $user, string $pwd)

Try a connection to te database

Arguments

  • $server string - Server address
  • $user string - Login for database connection
  • $pwd string - Password for database connection

connect

mixed DbCore::connect()

Open a connection

delete

boolean DbCore::delete(string $table, string $where, integer $limit, boolean $use_cache, boolean $add_prefix)

Execute a DELETE query

Arguments

  • $table string - Name of the table to delete
  • $where string - WHERE clause on query
  • $limit integer - Number max of rows to delete
  • $use_cache boolean - Use cache or not
  • $add_prefix boolean - Add or not DB_PREFIX before table name

disconnect

mixed DbCore::disconnect()

Close a connection

displayError

mixed DbCore::displayError(boolean $sql)

Display last SQL error

Arguments

  • $sql boolean

ds

mixed DbCore::ds($sql, $use_cache)

Arguments

  • $sql mixed
  • $use_cache mixed

escape

string DbCore::escape(string $string, boolean $html_ok)

Sanitize data which will be injected into SQL query

Arguments

  • $string string - SQL data which will be injected into SQL query
  • $html_ok boolean - Does data contain HTML code ? (optional)

execute

boolean DbCore::execute(string $sql, boolean $use_cache)

Execute a query

Arguments

  • $sql string
  • $use_cache boolean

executeS

array DbCore::executeS(string $sql, boolean $array, boolean $use_cache)

ExecuteS return the result of $sql as array

Arguments

  • $sql string - query to execute
  • $array boolean - return an array instead of a mysql_result object (deprecated since 1.5.0, use query method instead)
  • $use_cache boolean - if query has been already executed, use its result

getClass

string DbCore::getClass()

Get child layer class

getInstance

\Db DbCore::getInstance(boolean $master)

Get Db object instance

Arguments

  • $master boolean - Decides whether the connection to be returned by the master server or the slave server

getMsgError

mixed DbCore::getMsgError()

Returns the text of the error message from previous database operation

getNumberError

mixed DbCore::getNumberError()

Returns the number of the error from previous database operation

getRow

array DbCore::getRow(mixed $sql, boolean $use_cache)

getRow return an associative array containing the first row of the query This function automatically add "limit 1" to the query

Arguments

  • $sql mixed - the select query (without "LIMIT 1")
  • $use_cache boolean - find it in cache first

getValue

mixed DbCore::getValue(mixed $sql, boolean $use_cache)

getValue return the first item of a select query.

Arguments

  • $sql mixed
  • $use_cache boolean

getVersion

string DbCore::getVersion()

Get database version

hasTableWithSamePrefix

boolean DbCore::hasTableWithSamePrefix(string $server, string $user, string $pwd, string $db, string $prefix)

Try a connection to the database and check if at least one table with same prefix exists

Arguments

  • $server string - Server address
  • $user string - Login for database connection
  • $pwd string - Password for database connection
  • $db string - Database name
  • $prefix string - Tables prefix

insert

boolean DbCore::insert(string $table, array $data, boolean $null_values, boolean $use_cache, integer $type, boolean $add_prefix)

Execute an INSERT query

Arguments

  • $table string - Table name without prefix
  • $data array - Data to insert as associative array. If $data is a list of arrays, multiple insert will be done
  • $null_values boolean - If we want to use NULL values instead of empty quotes
  • $use_cache boolean
  • $type integer - Must be Db::INSERT or Db::INSERT_IGNORE or Db::REPLACE
  • $add_prefix boolean - Add or not DB_PREFIX before table name

nextRow

mixed DbCore::nextRow(mixed $result)

Get next row for a query which doesn't return an array

Arguments

  • $result mixed

numRows

integer DbCore::numRows()

Get number of rows for last result

ps

mixed DbCore::ps($sql, $use_cache)

Arguments

  • $sql mixed
  • $use_cache mixed

q

mixed DbCore::q(string $sql, boolean $use_cache)

Execute a query

Arguments

  • $sql string
  • $use_cache boolean

query

mixed DbCore::query(string $sql)

Execute a query and get result ressource

Arguments

  • $sql string

s

mixed DbCore::s($sql, $use_cache)

Arguments

  • $sql mixed
  • $use_cache mixed

set_db

mixed DbCore::set_db($db_name)

Arguments

  • $db_name mixed

update

boolean DbCore::update(string $table, array $data, string $where, integer $limit, boolean $null_values, boolean $use_cache, boolean $add_prefix)

Arguments

  • $table string - Table name without prefix
  • $data array - Data to insert as associative array. If $data is a list of arrays, multiple insert will be done
  • $where string - WHERE condition
  • $limit integer
  • $null_values boolean - If we want to use NULL values instead of empty quotes
  • $use_cache boolean
  • $add_prefix boolean - Add or not DB_PREFIX before table name