XOOPS  2.6.0
mysqldatabase.php
Go to the documentation of this file.
1 <?php
31 {
32 
36  private $lastResult = null;
37 
43  public $conn;
44 
50  private $connect = false;
51 
57  private $selectdb;
58 
64  protected function deprecated()
65  {
66  static $warning_issued = false;
67  if (!$warning_issued) {
68  $warning_issued = true;
69  $stack = debug_backtrace();
70  $frame = $stack[1];
71  Xoops::getInstance()->deprecated(
72  'Legacy XoopsDB is deprecated since 2.6.0; all calls should be using Doctrine through $xoops->db(). '
73  . 'Called from ' . $frame['function'] . '() in ' . $frame['file'] . ' line '. $frame['line']
74  );
75  }
76  }
77 
78 
87  public function connect($selectdb = true)
88  {
89  $this->connect = (is_object($this->conn));
90  $this->selectdb = $selectdb;
91  $this->allowWebChanges = ($_SERVER['REQUEST_METHOD'] != 'GET');
92  return $this->connect;
93  }
94 
95 
107  public function genId($sequence)
108  {
109  $this->deprecated();
110  return 0; // will use auto_increment
111  }
112 
121  public function fetchRow($result)
122  {
123  $this->deprecated();
124  if (!is_object($result)) {
125  return null;
126  }
127  return $result->fetch(\PDO::FETCH_NUM);
128  }
129 
138  public function fetchArray($result)
139  {
140  $this->deprecated();
141 
142  if (!is_object($result)) {
143  return null;
144  }
145  return $result->fetch(\PDO::FETCH_ASSOC);
146  }
147 
156  public function fetchBoth($result)
157  {
158  $this->deprecated();
159 
160  if (!is_object($result)) {
161  return null;
162  }
163  return $result->fetch(\PDO::FETCH_BOTH);
164  }
165 
174  public function fetchObject($result)
175  {
176  $this->deprecated();
177 
178  if (!is_object($result)) {
179  return null;
180  }
181  return $result->fetch(\PDO::FETCH_OBJ);
182  }
183 
190  public function getInsertId()
191  {
192  $this->deprecated();
193  return $this->conn->lastInsertId();
194  }
195 
204  public function getRowsNum($result)
205  {
206  Xoops::getInstance()->deprecated('getRowsNum is deprecated and not dependable.');
207  //$this->deprecated();
208  return $result->rowCount();
209  }
210 
217  public function getAffectedRows()
218  {
219  $this->deprecated();
220  return $this->lastResult->rowCount();
221  }
222 
229  public function close()
230  {
231  $this->deprecated();
232  return $this->conn->close();
233  }
234 
243  public function freeRecordSet($result)
244  {
245  $this->deprecated();
246 
247  return $result->closeCursor();
248  }
249 
257  public function error()
258  {
259  $this->deprecated();
260 
261  return $this->conn->errorInfo();
262  }
263 
272  public function errno()
273  {
274  $this->deprecated();
275 
276  return $this->conn->errorCode();
277  }
278 
288  public function quoteString($str)
289  {
290  $this->deprecated();
291 
292  return $this->quote($str);
293  }
294 
303  public function quote($string)
304  {
305  $this->deprecated();
306 
307  return $this->conn->quote($string);
308  }
309 
318  public function escape($string)
319  {
320  $this->deprecated();
321 
322  $string = $this->quote($input);
323  return substr($string, 1, -1);
324  }
325 
337  public function queryF($sql, $limit = 0, $start = 0)
338  {
339  $this->deprecated();
340 
341  if (!empty($limit)) {
342  if (empty($start)) {
343  $start = 0;
344  }
345  $sql = $sql . ' LIMIT ' . (int) $start . ', ' . (int) $limit;
346  }
347  $xoopsPreload = XoopsPreload::getInstance();
348  $xoopsPreload->triggerEvent('core.database.query.start');
349  try {
350  $result = $this->conn->query($sql);
351  } catch (Exception $e) {
352  $result=false;
353  }
354  $this->lastResult = $result;
355  $xoopsPreload->triggerEvent('core.database.query.end');
356 
357  if ($result) {
358  $xoopsPreload->triggerEvent('core.database.query.success', (array($sql)));
359  return $result;
360  } else {
361  $xoopsPreload->triggerEvent('core.database.query.failure', (array($sql, $this)));
362  return false;
363  }
364  }
365 
379  public function query($sql, $limit = 0, $start = 0)
380  {
381  $this->deprecated();
382 
383  }
384 
394  public function queryFromFile($file)
395  {
396  $this->deprecated();
397 
398  if (false !== ($fp = fopen($file, 'r'))) {
399  $sql_queries = trim(fread($fp, filesize($file)));
400  SqlUtility::splitMySqlFile($pieces, $sql_queries);
401  foreach ($pieces as $query) {
402  // [0] contains the prefixed query
403  // [4] contains unprefixed table name
404  $prefixed_query
405  = SqlUtility::prefixQuery(trim($query), $this->prefix());
406  if ($prefixed_query != false) {
407  $this->query($prefixed_query[0]);
408  }
409  }
410  return true;
411  }
412  return false;
413  }
414 
424  public function getFieldName($result, $offset)
425  {
426  $this->deprecated();
427 
428  try {
429  $temp = $result->getColumnMeta($offset);
430  return $temp['name'];
431  } catch (PDOException $e) {
432  return null;
433  }
434 
435  }
436 
446  public function getFieldType($result, $offset)
447  {
448  $this->deprecated();
449 
450  try {
451  $temp = ($result->getColumnMeta($offset));
452  $t = $temp['native_type'];
453 
454  $temp = (string)(
455  ((($t == 'STRING') || ($t == 'VAR_STRING') ) ? 'string' : '' ) .
456  ( (in_array($t, array('TINY', 'SHORT', 'LONG', 'LONGLONG', 'INT24'))) ? 'int' : '' ) .
457  ( (in_array($t, array('FLOAT', 'DOUBLE', 'DECIMAL', 'NEWDECIMAL'))) ? 'real' : '' ) .
458  ( ($t == 'TIMESTAMP') ? 'timestamp' : '' ) .
459  ( ($t == 'YEAR') ? 'year' : '') .
460  ( (($t == 'DATE') || ($t == 'NEWDATE') ) ? 'date' : '' ) .
461  ( ($t == 'TIME') ? 'time' : '' ) .
462  ( ($t == 'SET') ? 'set' : '' ) .
463  ( ($t == 'ENUM') ? 'enum' : '' ) .
464  ( ($t == 'GEOMETRY') ? 'geometry' : '' ) .
465  ( ($t == 'DATETIME') ? 'datetime' : '' ) .
466  ( (in_array($t, array('TINY_BLOB', 'BLOB', 'MEDIUM_BLOB', 'LONG_BLOB' ))) ? 'blob' : '' ) .
467  ( ($t == 'NULL') ? 'null' : '' )
468  );
469  return $temp;
470  } catch (PDOException $e) {
471  return null;
472  }
473  }
474 
483  public function getFieldsNum($result)
484  {
485  $this->deprecated();
486 
487  return $result->columnCount();
488  }
489 }
static prefixQuery($query, $prefix)
Definition: sqlutility.php:126
static getInstance()
Definition: Events.php:57
connect($selectdb=true)
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$query
Definition: index.php:37
$result
Definition: pda.php:33
$_SERVER['REQUEST_URI']
prefix($tablename= '')
Definition: database.php:76
static splitMySqlFile(&$ret, $sql)
Definition: sqlutility.php:43
getFieldType($result, $offset)
$sql
Definition: pda.php:32
$limit
Definition: findusers.php:202
query($sql, $limit=0, $start=0)
queryF($sql, $limit=0, $start=0)
$start
getFieldName($result, $offset)