PHP Class DBmysql, glpi

Afficher le fichier Open project: glpi-project/glpi Class Usage Examples

Méthodes publiques

Свойство 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

Méthodes publiques

Méthode 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 méthode

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

affected_rows() public méthode

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

checkForCrashedTables() public static méthode

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

close() public méthode

Close MySQL connection
public close ( ) : TRUE
Résultat TRUE on success or FALSE on failure.

connect() public méthode

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

data_seek() public méthode

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
Résultat boolean

errno() public méthode

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

error() public méthode

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

escape() public méthode

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
Résultat String escaped

fetch_array() public méthode

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
Résultat result array

fetch_assoc() public méthode

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

fetch_row() public méthode

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

field_flags() public méthode

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

field_name() public méthode

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
Résultat name of the field

free_result() public méthode

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

getInfo() public méthode

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

getLock() public méthode

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

insert_id() public méthode

Give ID of the last insert item by Mysql
public insert_id ( ) : item
Résultat item ID

isMySQLStrictMode() static public méthode

static public isMySQLStrictMode ( &$msg )

isSlave() public méthode

is a slave database ?
public isSlave ( ) : boolean
Résultat boolean

list_fields() public méthode

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)
Résultat list of fields

list_tables() public méthode

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

num_fields() public méthode

Give number of fields of a Mysql result
public num_fields ( $result ) : number
$result MySQL result handler
Résultat number of fields

numrows() public méthode

Give number of rows of a Mysql result
public numrows ( $result ) : number
$result MySQL result handler
Résultat number of rows

optimize_tables() static public méthode

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)
Résultat number of tables

prepare() public méthode

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

query() public méthode

Execute a MySQL query
public query ( $query ) : Query
$query Query to execute
Résultat Query result handler

queryOrDie() public méthode

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

releaseLock() public méthode

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

request() public méthode

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
Résultat DBIterator

result() public méthode

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

runFile() public méthode

Execute all the request in a file
public runFile ( $path ) : boolean
$path string with file full path
Résultat 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