OPiQuotations  v.03.00.00 — April 5, 2019
Public Member Functions | Protected Attributes | List of all members
OPiQuotations\Db Class Reference

Public Member Functions

 __construct ($host, $user, $password, $db_name)
 Open the connection to the database $db_name. More...
 
 __destruct ()
 Close the connection to the database. More...
 
 is_connected ()
 If connection is ok then return true else return false. More...
 
 escape ($s)
 Return the string with its special characters escaped for use in a SQL statement. More...
 
 list_to_assoc ($table)
 Return a associative table id => array(name, number of use) of elements of the table. More...
 
 nb ($is_maxim=null)
 Return the numbers of quotations and/or maxims. More...
 
 query_insert ($query)
 Execute the MySQL query INSERT. More...
 
 query_quotations ($where='', $order='', $limit=null, $offset=null)
 Return an array with all OPiQuotation that match with the SQL $where condition in order specified by $order. More...
 
 query_quotations_nb ($where='')
 Return the number of all OPiQuotation that match with the SQL $where condition. More...
 
 to_string ($x)
 Return escaped and quoted $x (converted to string). More...
 
 to_string_or_NULL ($x)
 If $x === null then return 'NULL' else return to_string($x). More...
 

Protected Attributes

 $connect
 Connection to the MySQL database. More...
 

Detailed Description

Class to connect and deal to the MySQL database.

Definition at line 28 of file Db.inc.

Constructor & Destructor Documentation

◆ __construct()

OPiQuotations\Db::__construct (   $host,
  $user,
  $password,
  $db_name 
)

Open the connection to the database $db_name.

If connection fails then write a message in the errors log file.

See is_connected() function.

Parameters
string$hostHost name or IP address of the server
string$userMySQL user name
string$passwordMySQL password
string$db_nameName of the database

Definition at line 43 of file Db.inc.

References OPiQuotations\to_log().

◆ __destruct()

OPiQuotations\Db::__destruct ( )

Close the connection to the database.

Definition at line 77 of file Db.inc.

Member Function Documentation

◆ escape()

OPiQuotations\Db::escape (   $s)

Return the string with its special characters escaped for use in a SQL statement.

Parameters
string$s
Returns
string

Definition at line 107 of file Db.inc.

◆ is_connected()

OPiQuotations\Db::is_connected ( )

If connection is ok then return true else return false.

Returns
bool

Definition at line 93 of file Db.inc.

◆ list_to_assoc()

OPiQuotations\Db::list_to_assoc (   $table)

Return a associative table id => array(name, number of use) of elements of the table.

Parameters
string$table(must be 'author', 'nation', 'subject' or 'work')
Returns
array[array]

Definition at line 126 of file Db.inc.

References OPiQuotations\Db\list_to_assoc(), and OPiQuotations\to_log().

Referenced by OPiQuotations\Db\list_to_assoc().

◆ nb()

OPiQuotations\Db::nb (   $is_maxim = null)

Return the numbers of quotations and/or maxims.

If $is_maxim === null then return the numbers of quotations/maxims,
if $is_maxim === false then return the numbers of quotations,
if $is_maxim === true then return the numbers of maxims.

Parameters
null | bool$is_maxim
Returns
int >= 0

Definition at line 192 of file Db.inc.

References $result, and OPiQuotations\to_log().

◆ query_insert()

OPiQuotations\Db::query_insert (   $query)

Execute the MySQL query INSERT.

If insertion is ok then return true, else return false.

Parameters
string$queryValid MySQL query
Returns
bool

Definition at line 245 of file Db.inc.

References OPiQuotations\Db\query_insert(), and OPiQuotations\to_log().

Referenced by OPiQuotations\Db\query_insert().

◆ query_quotations()

OPiQuotations\Db::query_quotations (   $where = '',
  $order = '',
  $limit = null,
  $offset = null 
)

Return an array with all OPiQuotation that match with the SQL $where condition in order specified by $order.

If $limit is not null then return only $limit OPiQuotation.

If $limit and $offset are not null then return only $limit OPiQuotation from $offset.

Warning
Use escape() with each string piece of $where if necessary.
Parameters
string$whereValid WHERE clause of the SELECT MySQL command used (see http://dev.mysql.com/doc/refman/5.1/en/select.html )
string$orderValid ORDER clause of the SELECT MySQL command used (see http://dev.mysql.com/doc/refman/5.1/en/select.html )
null | int$limit(must be >= 0)
null | int$offset(must be >= 0)
Returns
OPiQuotation[]

Definition at line 295 of file Db.inc.

References $id, $quot, $result, $selection, and OPiQuotations\to_log().

Referenced by OPiQuotations\Db\query_quotations_nb().

◆ query_quotations_nb()

OPiQuotations\Db::query_quotations_nb (   $where = '')

Return the number of all OPiQuotation that match with the SQL $where condition.

Warning
Use escape() with each string piece of $where if necessary.
Parameters
string$whereValid WHERE clause of the SELECT MySQL command used (see http://dev.mysql.com/doc/refman/5.1/en/select.html )
Returns
int

Definition at line 468 of file Db.inc.

References OPiQuotations\Db\query_quotations(), and OPiQuotations\to_log().

◆ to_string()

OPiQuotations\Db::to_string (   $x)

Return escaped and quoted $x (converted to string).

Parameters
null | mixed$x
Returns
string

Definition at line 524 of file Db.inc.

◆ to_string_or_NULL()

OPiQuotations\Db::to_string_or_NULL (   $x)

If $x === null then return 'NULL' else return to_string($x).

Parameters
null | mixed$x
Returns
string

Definition at line 539 of file Db.inc.

Member Data Documentation

◆ $connect

mysqli OPiQuotations\Db::$connect
protected

Connection to the MySQL database.

Definition at line 551 of file Db.inc.


The documentation for this class was generated from the following file: