Mercurial > defr > DualBlog
view includes/class.dataaccess.php @ 83:d49afe579884
DataAccess: Passe debugQuery en mysqli aussi
author | Franck Deroche <franck@defr.org> |
---|---|
date | Thu, 22 Nov 2018 23:13:52 +0100 |
parents | e4e50d4d3b7a |
children | e37ef9a81737 |
line wrap: on
line source
<?php class DataAccess { var $host; var $user; var $pass; var $db; var $link; var $connOpen; var $results; var $queries; var $_nbQueries; var $_inError; function DataAccess($host=DB_HOST, $user=DB_USER, $pass=DB_PASSWORD, $db=DB_NAME) { $this->host=$host; $this->user=$user; $this->pass=$pass; $this->db = $db; $this->connOpen = 0; $this->_nbQueries = 0; $this->_inError = false; $this->queries = array(); $this->results = array(); $this->Connect(); } function Connect() { if($this->connOpen == 0) { $this->link = mysqli_connect($this->host, $this->user, $this->pass, $this->db); if($this->link === false) $this->_inError = true; else mysqli_set_charset($this->link, 'utf8'); } $this->connOpen++; } function Query($query, $id=0) { $this->_nbQueries++; $this->queries[$id]=$query; $this->Connect(); $this->results[$id]=mysqli_query($this->link, $this->queries[$id]); $this->Close(); if(@$num_rows=mysqli_num_rows($this->results[$id])) return $num_rows; return 0; } function debugQuery($query, $id=0) { $rv = $this->Query($query, $id); if(mysqli_errno($this->link) !== 0) echo("<span class='menu'>\n Query : {$query}<br />\n MySQL Answer : " . mysql_error() . "</span>"); return $rv; } function GetRow($id=0) { if(@$row=mysqli_fetch_array($this->results[$id])) { return $row; } return 0; } function Close() { $this->connOpen--; if($this->connOpen == 0) { mysqli_close($this->link); } } function getNbQueries() { return $this->_nbQueries; } function formatDate($timestamp, $decallage=2, $pattern='d/m/Y H:i:s') { return gmdate($pattern, $timestamp + $decallage * 3600); } function isInError() { return $this->_inError; } } ?>