PDO Mysql Adapter.

The default and preferred DB adapter to use.

package LudoDB
author Alf Magne Kalleland

 Methods

Constructor

__construct() 
Inherited
inherited_from \LudoDB::__construct()

Connect to database

connect() : mixed

Exceptions

\LudoDBConnectionException

Returns

mixed

Return number of rows.

countRows($sql, array $params) : int

Example

$count = LudoDB::getInstance()->countRows("select * from city where country=?", array("Norway"));

Parameters

$sql

$params

array

Returns

int

Create database with given name

createDatabase($name) 
InheritedStatic
inherited_from \LudoDB::createDatabase()

Parameters

$name

Returns true if database with given name exists.

databaseExists($name) : bool
Inherited

Example:


$instance =
if(!LudoDB::getInstance()->databaseExists('nameOfDatabase')){
     LudoDB::getInstance()->createDatabase('nameOfDatabase');
}

inherited_from \LudoDB::databaseExists()

Parameters

$name

Returns

bool

Used to enable logging details(elapsed time and number of SQL queries) in JSON response from LudoDBRequestHandler

enableLogging() 
InheritedStatic
inherited_from \LudoDB::enableLogging()

Logs all sql queries to sql.txt

enableSqlLogging() 
InheritedStatic
inherited_from \LudoDB::enableSqlLogging()

Escape string - nothing to do here since we're using prepared statements.

escapeString($string) : mixed

Parameters

$string

Returns

mixed

Return name of database for database connection.

getDb() : String
InheritedStatic
inherited_from \LudoDB::getDb()

Returns

String

Return elapsed time for LudoDB operations.

getElapsed() : mixed
InheritedStatic
inherited_from \LudoDB::getElapsed()

Returns

mixed

Get last insert id

getInsertId() : int

Returns

int

Return new LudoDB object with connection to the database.

getInstance() : \LudoDB | \LudoDBMySql | \LudoDBMySqlI | \LudoDBPDO
InheritedStatic
inherited_from \LudoDB::getInstance()

Returns

Return number of executed SQL queries.

getQueryCount() : int
InheritedStatic
inherited_from \LudoDB::getQueryCount()

Returns

int

Return table definition, column names and column types for a table.

getTableDefinition(String $tableName) : array

Parameters

$tableName

String

Returns

array

Return value of first column in a query

getValue($sql, array $params) : null | array

Parameters

$sql

$params

array

Returns

nullarray

Returns true if we have a database connection.

hasConnection() : bool
InheritedStatic

Example:


LudoDB::hasConnection()

inherited_from \LudoDB::hasConnection()

Returns

bool

Returns true if connection type is PDO

hasPDO() : bool
InheritedStatic
inherited_from \LudoDB::hasPDO()

Returns

bool

Returns true if logging of SQL queries and elapsed time in LudoDBRequestHandler

isLoggingEnabled() : bool
InheritedStatic
inherited_from \LudoDB::isLoggingEnabled()

Returns

bool

Log SQL - this method is mostly used internally.

log($sql, array $arguments) 
Inherited
inherited_from \LudoDB::log()

Parameters

$sql

$arguments

array

Go to next row

nextRow(\mysqli_result | resource | \PDOStatement $result) : array

Parameters

$result

\mysqli_resultresource\PDOStatement

Returns

array

Get one row.

one($sql, array $params) : array | null

Parameters

$sql

$params

array

Returns

arraynull

Execute query and return resource.

query($sql, array $params) : bool | \mysqli_result | resource | \PDOStatement

Parameters

$sql

$params

array

Exceptions

\Exception

Returns

Set connection type, PDO|MySqlI|MySql

setConnectionType($type) 
InheritedStatic
inherited_from \LudoDB::setConnectionType()

Parameters

$type

Set name of database used in database connection.

setDb($dbName) 
InheritedStatic
inherited_from \LudoDB::setDb()

Parameters

$dbName

Set host for database connection.

setHost($host) 
InheritedStatic
inherited_from \LudoDB::setHost()

Parameters

$host

Set password for database connection.

setPassword($pwd) 
InheritedStatic
inherited_from \LudoDB::setPassword()

Parameters

$pwd

Set user name for database connection

setUser($user) 
InheritedStatic
inherited_from \LudoDB::setUser()

Parameters

$user

Returns true if given database table exists.

tableExists($tableName) : String
Inherited
inherited_from \LudoDB::tableExists()

Parameters

$tableName

Returns

String

Use this databsae.

useDatabase($name) 
Inherited
inherited_from \LudoDB::useDatabase()

Parameters

$name

Return specified host for database connection.

getHost() : String
InheritedStatic
inherited_from \LudoDB::getHost()

Returns

String

Return password for database connection.

getPassword() : String
InheritedStatic
inherited_from \LudoDB::getPassword()

Returns

String

Return username for database connection.

getUser() : String
InheritedStatic
inherited_from \LudoDB::getUser()

Returns

String

Return microtime

getTime() : mixed
InheritedStatic
inherited_from \LudoDB::getTime()

Returns

mixed

 Properties

 

$conn : \PDO
 

$logSQLs : bool
Inherited
inherited_from \LudoDB::$$logSQLs
 

$loggingEnabled : bool
Inherited
inherited_from \LudoDB::$$loggingEnabled
 

$queryCounter : int
Inherited
inherited_from \LudoDB::$$queryCounter
 

$startTime : float
Inherited
inherited_from \LudoDB::$$startTime
 

$connectionType : string
Inherited
inherited_from \LudoDB::$$connectionType
 

$instance : \LudoDB
Inherited
inherited_from \LudoDB::$$instance

 Constants

 

ADAPTER_MYSQL

ADAPTER_MYSQL 
Inherited
inherited_from \LudoDB::ADAPTER_MYSQL
 

ADAPTER_MYSQLI

ADAPTER_MYSQLI 
Inherited
inherited_from \LudoDB::ADAPTER_MYSQLI
 

ADAPTER_PDO

ADAPTER_PDO 
Inherited
inherited_from \LudoDB::ADAPTER_PDO
 

ADAPTER_PDO_ORACLE

ADAPTER_PDO_ORACLE 
Inherited
inherited_from \LudoDB::ADAPTER_PDO_ORACLE