Alternc  latest
Alternc logiel libre pour l'h├ębergement
 All Classes Namespaces Files Functions Variables Pages
DB_system Class Reference

Class for MySQL management in the panel. More...

+ Inheritance diagram for DB_system:

Public Member Functions

 __construct ()
 
 __construct ()
 
 __construct ($database, $user, $password)
 
 connect ($Database="", $Host="", $User="", $Password="")
 function for MySQL database connection management More...
 
 free ()
 Discard the query result. More...
 
 is_connected ()
 
 last_error ()
 
 query ($Query_String, $arguments=false)
 Perform a query. More...
 
 next_record ()
 walk result set More...
 
 lock ($table, $mode="write")
 table locking More...
 
 unlock ()
 table unlocking More...
 
 affected_rows ()
 evaluate the result (size, width) More...
 
 num_rows ()
 
 num_fields ()
 
 nf ()
 shorthand notation More...
 
 np ()
 
 f ($Name)
 
 current_record ()
 
 p ($Name)
 
 lastid ()
 
 quote ($string)
 Escape a string to use it into a SQL PDO query. More...
 
 exec ($query)
 Execute a direct query, not getting any result back. More...
 
 nextid ($seq_name)
 get next sequence numbers More...
 
 metadata ($table='', $full=false)
 DEPRECATED return table metadata. More...
 
 halt ($msg)
 private: error handling More...
 
 haltmsg ($msg)
 private: error handling More...
 
 table_names ()
 

Public Attributes

 $Record = array()
 

Detailed Description

Class for MySQL management in the panel.

Class for MySQL management in the bureau.

This class heriting from the db class of the phplib manages the connection to the MySQL database.

Definition at line 28 of file bootstrap.php.

Constructor & Destructor Documentation

DB_system::__construct ( )

Definition at line 29 of file bootstrap.php.

References $L_MYSQL_DATABASE, $L_MYSQL_HOST, $L_MYSQL_LOGIN, and $L_MYSQL_PWD.

29  {
31  parent::__construct($L_MYSQL_DATABASE, $L_MYSQL_HOST, $L_MYSQL_LOGIN, $L_MYSQL_PWD);
32  }
global $L_MYSQL_DATABASE
Definition: bootstrap.php:22
global $L_MYSQL_PWD
Definition: bootstrap.php:22
global $L_MYSQL_LOGIN
Definition: bootstrap.php:22
global $L_MYSQL_HOST
Definition: bootstrap.php:22
DB_system::__construct ( )

Definition at line 113 of file config.php.

References $L_MYSQL_DATABASE, $L_MYSQL_HOST, $L_MYSQL_LOGIN, and $L_MYSQL_PWD.

113  {
115  parent::__construct($L_MYSQL_DATABASE, $L_MYSQL_HOST, $L_MYSQL_LOGIN, $L_MYSQL_PWD);
116  }
global $L_MYSQL_DATABASE
Definition: bootstrap.php:22
global $L_MYSQL_PWD
Definition: bootstrap.php:22
global $L_MYSQL_LOGIN
Definition: bootstrap.php:22
global $L_MYSQL_HOST
Definition: bootstrap.php:22
DB_system::__construct (   $database,
  $user,
  $password 
)

Definition at line 122 of file bootstrap.php.

References $database, $password, and $user.

122  {
123  parent::__construct($database, '127.0.0.1', $user, $password);
124  }
$user
Definition: bootstrap.php:84
foreach(array(ALTERNC_MAIL, ALTERNC_HTML, ALTERNC_LOGS) as $crdir) $database
Definition: bootstrap.php:83
$password
Definition: bootstrap.php:85

Member Function Documentation

DB_Sql::affected_rows ( )
inherited

evaluate the result (size, width)

Definition at line 271 of file db_mysql.php.

271  {
272  return $this->pdo_query->rowCount();
273  }
DB_Sql::connect (   $Database = "",
  $Host = "",
  $User = "",
  $Password = "" 
)
inherited

function for MySQL database connection management

This function manages the connection to the MySQL database.

Parameters
$Databasename of the database
$HostDNS of the MySQL hosting server
$Userthe user's name
$Passwordthe user's password
Returns
the class variable $Link_ID

Definition at line 86 of file db_mysql.php.

References DB_Sql\$Database, DB_Sql\$Host, DB_Sql\$Password, DB_Sql\$User, and DB_Sql\halt().

86  {
87  $this->halt('Mysql::connect() : This function should no longer be used');
88  /* Handle defaults */
89  if ("" == $Database)
91  if ("" == $Host)
93  if ("" == $User)
95  if ("" == $Password)
97 
98  if (!$this->pdo_instance) {
99  $dsn = sprintf('mysql:dbname=%s;host=%s', $Database, $Host);
100 
101  try {
102  $this->pdo_instance = new PDO($dsn, $User, $Password);
103  } catch (PDOException $e) {
104  $this->halt("Mysql::PDO_instance" . $e->getMessage());
105  return FALSE;
106  }
107  }
108 
109  return True;
110  }
$Database
Definition: db_mysql.php:31
halt($msg)
private: error handling
Definition: db_mysql.php:398
$Password
Definition: db_mysql.php:33
DB_Sql::current_record ( )
inherited

Definition at line 306 of file db_mysql.php.

References DB_Sql\$Record.

306  {
307  return $this->Record;
308  }
DB_Sql::exec (   $query)
inherited

Execute a direct query, not getting any result back.

Parameters
querystring query to execute
Returns
integer the number of affected rows

Definition at line 336 of file db_mysql.php.

References $query.

336  {
337  return $this->pdo_instance->exec($query);
338  }
$query
Definition: 3.0.0~3.php:37
DB_Sql::f (   $Name)
inherited
Parameters
string$Name
Returns
integer

Definition at line 298 of file db_mysql.php.

Referenced by DB_Sql\nextid().

298  {
299  if (isset($this->Record[$Name]))
300  return $this->Record[$Name];
301  else
302  return false;
303  }
DB_Sql::free ( )
inherited

Discard the query result.

This function discards the last query result.

Definition at line 117 of file db_mysql.php.

Referenced by DB_Sql\next_record().

117  {
118  $this->pdo_query->closeCursor();
119  }
DB_Sql::halt (   $msg)
inherited

private: error handling

Definition at line 398 of file db_mysql.php.

References $msg, and DB_Sql\haltmsg().

Referenced by DB_Sql\connect(), DB_Sql\lock(), DB_Sql\next_record(), DB_Sql\nextid(), DB_Sql\query(), and DB_Sql\unlock().

398  {
399  if ($this->Halt_On_Error == "no")
400  return;
401 
402  $this->haltmsg($msg);
403 
404  if ($this->Halt_On_Error != "report")
405  die("Session halted.");
406  }
$msg
Definition: config.php:155
haltmsg($msg)
private: error handling
Definition: db_mysql.php:412
DB_Sql::haltmsg (   $msg)
inherited

private: error handling

Definition at line 412 of file db_mysql.php.

References $msg.

Referenced by DB_Sql\halt().

412  {
413  printf("</td></tr></table><b>Database error:</b> %s<br />\n", $msg);
414  printf("<b>MySQL Error</b>: %s (%s)<br />\n",
415  $this->Errno,
416  implode("\n", $this->Error));
417  }
$msg
Definition: config.php:155
DB_Sql::is_connected ( )
inherited

Definition at line 122 of file db_mysql.php.

Referenced by DB_Sql\lock(), DB_Sql\nextid(), DB_Sql\query(), and DB_Sql\unlock().

122  {
123  return $this->pdo_instance != FALSE;
124  }
DB_Sql::last_error ( )
inherited

Definition at line 127 of file db_mysql.php.

References DB_Sql\$Error.

127  {
128  return $this->Error;
129  }
DB_Sql::lastid ( )
inherited

Definition at line 316 of file db_mysql.php.

316  {
317  return $this->pdo_instance->lastInsertId();
318  }
DB_Sql::lock (   $table,
  $mode = "write" 
)
inherited

table locking

Definition at line 226 of file db_mysql.php.

References $key, $query, $value, each(), DB_Sql\halt(), DB_Sql\is_connected(), and DB_Sql\query().

Referenced by DB_Sql\nextid().

226  {
227  if (!$this->is_connected())
228  return FALSE;
229 
230  $query="lock tables ";
231  if (is_array($table)) {
232  while (list($key,$value)=each($table)) {
233  if ($key=="read" && $key!=0) {
234  $query.="$value read, ";
235  } else {
236  $query.="$value $mode, ";
237  }
238  }
239  $query=substr($query,0,-2);
240  } else {
241  $query.="$table $mode";
242  }
243 
244 
245  if (!$this->query($query)) {
246  $this->halt("lock($table, $mode) failed.");
247  return FALSE;
248  }
249 
250  return TRUE;
251 
252  }
halt($msg)
private: error handling
Definition: db_mysql.php:398
$query
Definition: 3.0.0~3.php:37
is_connected()
Definition: db_mysql.php:122
$value
x each(["height","width"], function(e, n){x.cssHooks[n]={get:function(e, r, i){return r?0===e.offsetWidth &&Xt.test(x.css(e,"display"))?x.swap(e, Qt, function(){return sn(e, n, i)}):sn(e, n, i):t}, set:function(e, t, r){var i=r &&Rt(e);return on(e, t, r?an(e, n, r, x.support.boxSizing &&"border-box"===x.css(e,"boxSizing",!1, i), i):0)}}})
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
query($Query_String, $arguments=false)
Perform a query.
Definition: db_mysql.php:141
DB_Sql::metadata (   $table = '',
  $full = false 
)
inherited

DEPRECATED return table metadata.

Definition at line 389 of file db_mysql.php.

References $msg.

389  {
390  global $msg;
391  $msg->raise("ERROR", 'Mysql', 'function is no longer implemented (metadata())');
392  return FALSE;
393  }
$msg
Definition: config.php:155
DB_Sql::next_record ( )
inherited

walk result set

This function tests if a new record is available in the current query result.

Returns
TRUE if a new record is available

Definition at line 202 of file db_mysql.php.

References DB_Sql\free(), and DB_Sql\halt().

Referenced by DB_Sql\nextid(), and DB_Sql\table_names().

202  {
203  if (!$this->pdo_query) {
204  $this->halt("next_record called with no query pending.");
205  return FALSE;
206  }
207 
208  $this->Record = $this->pdo_query->fetch(PDO::FETCH_BOTH);
209  $this->Row++;
210  $this->Errno = $this->pdo_query->errorCode();
211  $this->Error = $this->pdo_query->errorInfo();
212 
213  if ($this->Record == FALSE) {
214  if ($this->Auto_Free)
215  $this->free();
216  return FALSE;
217  }
218 
219  return TRUE;
220  }
halt($msg)
private: error handling
Definition: db_mysql.php:398
free()
Discard the query result.
Definition: db_mysql.php:117
DB_Sql::nextid (   $seq_name)
inherited

get next sequence numbers

Definition at line 344 of file db_mysql.php.

References $id, $q, DB_Sql\f(), DB_Sql\halt(), DB_Sql\is_connected(), DB_Sql\lock(), DB_Sql\next_record(), DB_Sql\query(), and DB_Sql\unlock().

344  {
345  if (!$this->is_connected())
346  return FALSE;
347 
348  if ($this->lock($this->Seq_Table)) {
349  /* get sequence number (locked) and increment */
350  $q = sprintf("select nextid from %s where seq_name = '%s'",
351  $this->Seq_Table,
352  $seq_name);
353  $this->query($q);
354  $this->next_record();
355 
356  $id = $this->f('nextid');
357 
358  /* No current value, make one */
359  if (!$id) {
360  $currentid = 0;
361  $q = sprintf("insert into %s values('%s', %s)",
362  $this->Seq_Table,
363  $seq_name,
364  $currentid);
365  $this->query($q);
366  } else {
367  $currentid = $id;
368  }
369 
370  $nextid = $currentid + 1;
371  $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'",
372  $this->Seq_Table,
373  $nextid,
374  $seq_name);
375  $this->query($q);
376  $this->unlock();
377  } else {
378  $this->halt("cannot lock ".$this->Seq_Table." - has it been created?");
379  return FALSE;
380  }
381 
382  return $nextid;
383  }
f($Name)
Definition: db_mysql.php:298
halt($msg)
private: error handling
Definition: db_mysql.php:398
is_connected()
Definition: db_mysql.php:122
lock($table, $mode="write")
table locking
Definition: db_mysql.php:226
next_record()
walk result set
Definition: db_mysql.php:202
unlock()
table unlocking
Definition: db_mysql.php:257
query($Query_String, $arguments=false)
Perform a query.
Definition: db_mysql.php:141
if(!isset($is_include)) if(!$key &&!$crt) $id
DB_Sql::nf ( )
inherited

shorthand notation

Definition at line 285 of file db_mysql.php.

References DB_Sql\num_rows().

285  {
286  return $this->num_rows();
287  }
num_rows()
Definition: db_mysql.php:274
DB_Sql::np ( )
inherited

Definition at line 289 of file db_mysql.php.

References DB_Sql\num_rows(), and print.

289  {
290  print $this->num_rows();
291  }
print
Definition: mail_add.php:92
num_rows()
Definition: db_mysql.php:274
DB_Sql::num_fields ( )
inherited

Definition at line 278 of file db_mysql.php.

278  {
279  return $this->pdo_query->columnCount();
280  }
DB_Sql::num_rows ( )
inherited

Definition at line 274 of file db_mysql.php.

Referenced by DB_Sql\nf(), and DB_Sql\np().

274  {
275  return $this->pdo_query->rowCount();
276  }
DB_Sql::p (   $Name)
inherited

Definition at line 311 of file db_mysql.php.

References print.

Referenced by DB_Sql\table_names().

311  {
312  print $this->Record[$Name];
313  }
print
Definition: mail_add.php:92
DB_Sql::query (   $Query_String,
  $arguments = false 
)
inherited

Perform a query.

This function performs the MySQL query described in the string parameter

Parameters
astring describing the MySQL query
argumentsis an optionnal array for future use with PDO parametrized requests
Returns
the $Query_ID class variable (null if fails)

Definition at line 141 of file db_mysql.php.

References DB_Sql\$Query_String, DB_Sql\halt(), DB_Sql\is_connected(), and THROW_EXCEPTIONS.

Referenced by DB_Sql\lock(), DB_Sql\nextid(), DB_Sql\table_names(), and DB_Sql\unlock().

141  {
142  global $debug_alternc;
143 
144  if (empty($Query_String) || !$this->is_connected())
145  return FALSE;
146 
147  $this->Query_String = $Query_String;
148  if ($this->Debug)
149  printf("Debug: query = %s<br />\n", $Query_String);
150 
151  $debug_chrono_start = microtime(true);
152 
153  if ($arguments===false) {
154  $this->pdo_query = $this->pdo_instance->query($Query_String);
155  $exec_state = is_object($this->pdo_query);
156 
157  } else {
158 
159  $this->pdo_query = $this->pdo_instance->prepare($this->Query_String);
160  $exec_state = ($arguments) ? $this->pdo_query->execute($arguments)
161  : $this->pdo_query->execute();
162  // WARNING: this ternary is when we pass array() as $arguments
163  }
164 
165  $debug_chrono_start = (microtime(true) - $debug_chrono_start)*1000;
166  $this->Row = 0;
167 
168  if ($exec_state == FALSE) {
169  if (is_object($this->pdo_query)) {
170  $this->Errno = $this->pdo_query->errorCode();
171  $this->Error = $this->pdo_query->errorInfo();
172  } else {
173  $this->Errno = $this->pdo_instance->errorCode();
174  $this->Error = $this->pdo_instance->errorInfo();
175  }
176 
177  if( defined("THROW_EXCEPTIONS") && THROW_EXCEPTIONS ){
178  throw new \Exception("Mysql query failed : $this->Error");
179  }
180  $this->halt("SQL Error: ".$Query_String);
181  return FALSE;
182  }
183 
184  if (isset($debug_alternc)) {
185  $debug_alternc->add("SQL Query : (".substr($debug_chrono_start,0,5)." ms)\t $Query_String");
186  $debug_alternc->nb_sql_query++;
187  $debug_alternc->tps_sql_query += $debug_chrono_start;
188  }
189 
190  return TRUE;
191  }
$Query_String
Definition: db_mysql.php:51
halt($msg)
private: error handling
Definition: db_mysql.php:398
is_connected()
Definition: db_mysql.php:122
const THROW_EXCEPTIONS
Definition: bootstrap.php:69
DB_Sql::quote (   $string)
inherited

Escape a string to use it into a SQL PDO query.

Parameters
stringstring to escape
Returns
string escaped string

Definition at line 326 of file db_mysql.php.

References $string.

326  {
327  return $this->pdo_instance->quote($string);
328  }
$string
Definition: logs_tail.php:38
DB_Sql::table_names ( )
inherited

Definition at line 420 of file db_mysql.php.

References DB_Sql\next_record(), DB_Sql\p(), and DB_Sql\query().

420  {
421  $this->query("SHOW TABLES");
422  $return = array();
423  while ($this->next_record())
424  $return[] = array('table_name' => $this->p(0), 'tablespace_name' => $this->Database, 'database' => $this->Database);
425 
426  return $return;
427  }
p($Name)
Definition: db_mysql.php:311
next_record()
walk result set
Definition: db_mysql.php:202
query($Query_String, $arguments=false)
Perform a query.
Definition: db_mysql.php:141
DB_Sql::unlock ( )
inherited

table unlocking

Definition at line 257 of file db_mysql.php.

References DB_Sql\halt(), DB_Sql\is_connected(), and DB_Sql\query().

Referenced by DB_Sql\nextid().

257  {
258  if (!$this->is_connected())
259  return FALSE;
260 
261  if (!$this->query('unlock tables')) {
262  $this->halt("unlock() failed.");
263  return FALSE;
264  }
265  }
halt($msg)
private: error handling
Definition: db_mysql.php:398
is_connected()
Definition: db_mysql.php:122
query($Query_String, $arguments=false)
Perform a query.
Definition: db_mysql.php:141

Member Data Documentation

DB_Sql::$Record = array()
inherited

Definition at line 42 of file db_mysql.php.

Referenced by DB_Sql\current_record().


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