PHP Class DBmysql, glpi

Datei anzeigen Open project: glpi-project/glpi Class Usage Examples

Public Properties

Property Type Description
$connected Is connected to the DB ?
$dbdefault ! Default Database
$dbh ! Database Handler
$dbhost ! Database Host - string or Array of string (round robin)
$dbpassword ! Database Password
$dbuser ! Database User
$error ! Database Error
$first_connection Is it a first connection ? Indicates if the first connection attempt is successful or not if first attempt fail -> display a warning which indicates that glpi is in readonly
$slave Slave management

Public Methods

Method Description
__construct ( $choice = NULL ) : nothing Constructor / Connect to the MySQL Database
affected_rows ( ) : number Get number of affected rows in previous MySQL operation
checkForCrashedTables ( ) : an Check for crashed MySQL Tables
close ( ) : TRUE Close MySQL connection
connect ( $choice = NULL ) : nothing Connect using current database settings
data_seek ( $result, $num ) : boolean Move current pointer of a Mysql result to the specific row
errno ( ) : error Returns the numerical value of the error message from previous MySQL operation
error ( ) : error Returns the text of the error message from previous MySQL operation
escape ( $string ) : String Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection
fetch_array ( $result ) : result Fetch array of the next row of a Mysql query Please prefer fetch_row or fetch_assoc
fetch_assoc ( $result ) : result Fetch assoc of the next row of a Mysql query
fetch_row ( $result ) : result Fetch row of the next row of a Mysql query
field_flags ( $result, $field ) : flags Get flags of a field of a mysql result
field_name ( $result, $nb ) : name Give name of a field of a Mysql result
free_result ( $result ) : Returns Free result memory
getInfo ( ) : Array Get information about DB connection for showSystemInformations
getLock ( $name ) : boolean Get a global DB lock
insert_id ( ) : item Give ID of the last insert item by Mysql
isMySQLStrictMode ( &$msg )
isSlave ( ) : boolean is a slave database ?
list_fields ( $table, $usecache = true ) : list List fields of a table
list_tables ( $table = "glpi_%" ) : list List tables in database
num_fields ( $result ) : number Give number of fields of a Mysql result
numrows ( $result ) : number Give number of rows of a Mysql result
optimize_tables ( $migration = NULL, $cron = false ) : number Optimize sql table
prepare ( $query ) : a Prepare a MySQL query
query ( $query ) : Query Execute a MySQL query
queryOrDie ( $query, $message = '' ) : Query Execute a MySQL query
releaseLock ( $name ) : boolean Release a global DB lock
request ( $tableorsql, $crit = "", $debug = false ) : DBIterator Instanciate a Simple DBIterator
result ( $result, $i, $field ) : Value Give result from a mysql result
runFile ( $path ) : boolean Execute all the request in a file

Method Details

__construct() public method

try to connect
public __construct ( $choice = NULL ) : nothing
$choice integer, host number (default NULL)
return nothing

affected_rows() public method

Get number of affected rows in previous MySQL operation
public affected_rows ( ) : number
return number of affected rows on success, and -1 if the last query failed.

checkForCrashedTables() public static method

Check for crashed MySQL Tables
public static checkForCrashedTables ( ) : an
return an array with supposed crashed table and check message

close() public method

Close MySQL connection
public close ( ) : TRUE
return TRUE on success or FALSE on failure.

connect() public method

Use dbhost, dbuser, dbpassword and dbdefault
public connect ( $choice = NULL ) : nothing
$choice integer, host number (default NULL)
return nothing

data_seek() public method

Move current pointer of a Mysql result to the specific row
public data_seek ( $result, $num ) : boolean
$result MySQL result handler
$num row to move current pointer
return boolean

errno() public method

Returns the numerical value of the error message from previous MySQL operation
public errno ( ) : error
return error number from the last MySQL function, or 0 (zero) if no error occurred.

error() public method

Returns the text of the error message from previous MySQL operation
public error ( ) : error
return error text from the last MySQL function, or '' (empty string) if no error occurred.

escape() public method

Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection
public escape ( $string ) : String
$string String to escape
return String escaped

fetch_array() public method

Fetch array of the next row of a Mysql query Please prefer fetch_row or fetch_assoc
public fetch_array ( $result ) : result
$result MySQL result handler
return result array

fetch_assoc() public method

Fetch assoc of the next row of a Mysql query
public fetch_assoc ( $result ) : result
$result MySQL result handler
return result associative array

fetch_row() public method

Fetch row of the next row of a Mysql query
public fetch_row ( $result ) : result
$result MySQL result handler
return result row

field_flags() public method

Get flags of a field of a mysql result
public field_flags ( $result, $field ) : flags
$result MySQL result handler
$field field name
return flags of the field

field_name() public method

Give name of a field of a Mysql result
public field_name ( $result, $nb ) : name
$result MySQL result handler
$nb number of columns of the field
return name of the field

free_result() public method

Free result memory
public free_result ( $result ) : Returns
$result MySQL result handler
return Returns TRUE on success or FALSE on failure.

getInfo() public method

Get information about DB connection for showSystemInformations
public getInfo ( ) : Array
return Array of label / value

getLock() public method

Get a global DB lock
public getLock ( $name ) : boolean
$name String : name of the lock
return boolean

insert_id() public method

Give ID of the last insert item by Mysql
public insert_id ( ) : item
return item ID

isMySQLStrictMode() static public method

static public isMySQLStrictMode ( &$msg )

isSlave() public method

is a slave database ?
public isSlave ( ) : boolean
return boolean

list_fields() public method

List fields of a table
public list_fields ( $table, $usecache = true ) : list
$table String table name condition
$usecache Boolean if use field list cache (default true)
return list of fields

list_tables() public method

List tables in database
public list_tables ( $table = "glpi_%" ) : list
$table table name condition (glpi_% as default to retrieve only glpi tables)
return list of tables

num_fields() public method

Give number of fields of a Mysql result
public num_fields ( $result ) : number
$result MySQL result handler
return number of fields

numrows() public method

Give number of rows of a Mysql result
public numrows ( $result ) : number
$result MySQL result handler
return number of rows

optimize_tables() static public method

Optimize sql table
static public optimize_tables ( $migration = NULL, $cron = false ) : number
$migration migration class (default NULL)
$cron to know if optimize must be done (false by default)
return number of tables

prepare() public method

Prepare a MySQL query
public prepare ( $query ) : a
$query Query to prepare
return a statement object or FALSE if an error occurred.

query() public method

Execute a MySQL query
public query ( $query ) : Query
$query Query to execute
return Query result handler

queryOrDie() public method

Execute a MySQL query
public queryOrDie ( $query, $message = '' ) : Query
$query Query to execute
$message explaination of query (default '')
return Query result handler

releaseLock() public method

Release a global DB lock
public releaseLock ( $name ) : boolean
$name String : name of the lock
return boolean

request() public method

Examples = foreach ($DB->request("select * from glpi_states") as $data) { ... } foreach ($DB->request("glpi_states") as $ID => $data) { ... } foreach ($DB->request("glpi_states", "ID=1") as $ID => $data) { ... } foreach ($DB->request("glpi_states", "", "name") as $ID => $data) { ... } foreach ($DB->request("glpi_computers",array("name"=>"SBEI003W","entities_id"=>1),array("serial","otherserial")) { ... }
public request ( $tableorsql, $crit = "", $debug = false ) : DBIterator
$tableorsql table name, array of names or SQL query
$crit string or array of filed/values, ex array("id"=>1), if empty => all rows (default '')
$debug for log the request (default false) Examples = array("id"=>NULL) array("OR"=>array("id"=>1, "NOT"=>array("state"=>3))); array("AND"=>array("id"=>1, array("NOT"=>array("state"=>array(3,4,5),"toto"=>2)))) FIELDS name or array of field names ORDER name or array of field names LIMIT max of row to retrieve START first row to retrieve
return DBIterator

result() public method

Give result from a mysql result
public result ( $result, $i, $field ) : Value
$result MySQL result handler
$i Row to give
$field Field to give
return Value of the Row $i and the Field $field of the Mysql $result

runFile() public method

Execute all the request in a file
public runFile ( $path ) : boolean
$path string with file full path
return boolean true if all query are successfull

Property Details

$connected public_oe property

Is connected to the DB ?
public $connected

$dbdefault public_oe property

! Default Database
public $dbdefault

$dbh public_oe property

! Database Handler
public $dbh

$dbhost public_oe property

! Database Host - string or Array of string (round robin)
public $dbhost

$dbpassword public_oe property

! Database Password
public $dbpassword

$dbuser public_oe property

! Database User
public $dbuser

$error public_oe property

! Database Error
public $error

$first_connection public_oe property

Is it a first connection ? Indicates if the first connection attempt is successful or not if first attempt fail -> display a warning which indicates that glpi is in readonly
public $first_connection

$slave public_oe property

Slave management
public $slave