Debug VMXTemplate, DatabaseMysql
parent
31d27904d2
commit
5b65c532fa
|
@ -6,42 +6,79 @@
|
||||||
* (c) Vitaliy Filippov, 2012
|
* (c) Vitaliy Filippov, 2012
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('MS_HASH', 0);
|
if (!defined('MS_HASH'))
|
||||||
define('MS_LIST', 1);
|
{
|
||||||
define('MS_ROW', 2);
|
define('MS_HASH', 0);
|
||||||
define('MS_ONE', 2);
|
define('MS_LIST', 1);
|
||||||
define('MS_COL', 4);
|
define('MS_ROW', 2);
|
||||||
define('MS_VALUE', 6);
|
define('MS_ONE', 2);
|
||||||
define('MS_RESULT', 8);
|
define('MS_COL', 4);
|
||||||
|
define('MS_VALUE', 6);
|
||||||
|
define('MS_RESULT', 8);
|
||||||
|
}
|
||||||
|
|
||||||
class DatabaseMysql
|
class DatabaseMysql
|
||||||
{
|
{
|
||||||
var $dbName;
|
var $host, $port, $socket, $username, $password, $dbName;
|
||||||
|
|
||||||
var $link;
|
var $link;
|
||||||
var $tableNames = array();
|
var $tableNames = array();
|
||||||
var $queryCount = 0;
|
var $queryCount = 0;
|
||||||
var $queryLogFile;
|
var $queryLogFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a MySQL connection object.
|
||||||
|
*
|
||||||
|
* @param string $host either 'host', 'host:port', or ':/var/run/mysqld/mysqld.sock'
|
||||||
|
* @param string $username
|
||||||
|
* @param string $password
|
||||||
|
* @param string $dbname
|
||||||
|
* @param string $port (optional)
|
||||||
|
* @param string $socket (optional)
|
||||||
|
*/
|
||||||
function __construct($host, $username, $password, $dbname, $port = NULL, $socket = NULL)
|
function __construct($host, $username, $password, $dbname, $port = NULL, $socket = NULL)
|
||||||
{
|
{
|
||||||
if ($socket !== NULL)
|
$host = explode(':', $host, 2);
|
||||||
|
if (!$host[0])
|
||||||
{
|
{
|
||||||
$this->link = new mysqli($host, $username, $password, $dbname, $port, $socket);
|
$socket = $host[1];
|
||||||
}
|
$host = 'localhost';
|
||||||
elseif ($port !== NULL)
|
|
||||||
{
|
|
||||||
$this->link = new mysqli($host, $username, $password, $dbname, $port);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->link = new mysqli($host, $username, $password, $dbname);
|
if ($host[1])
|
||||||
|
{
|
||||||
|
$port = $host[1];
|
||||||
|
}
|
||||||
|
$host = $host[0];
|
||||||
}
|
}
|
||||||
$this->dbName = $dbname;
|
$this->host = $host;
|
||||||
|
$this->username = $username;
|
||||||
|
$this->password = $password;
|
||||||
|
$this->dbname = $dbname;
|
||||||
|
$this->connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
function connect()
|
||||||
|
{
|
||||||
|
if ($this->socket !== NULL)
|
||||||
|
{
|
||||||
|
$this->link = new mysqli($this->host, $this->username, $this->password, $this->dbname, $this->port, $this->socket);
|
||||||
|
}
|
||||||
|
elseif ($this->port !== NULL)
|
||||||
|
{
|
||||||
|
$this->link = new mysqli($this->host, $this->username, $this->password, $this->dbname, $this->port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->link = new mysqli($this->host, $this->username, $this->password, $this->dbname);
|
||||||
|
}
|
||||||
|
$this->link->set_charset('utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDBName()
|
function getDBName()
|
||||||
{
|
{
|
||||||
return $this->dbName;
|
return $this->dbname;
|
||||||
}
|
}
|
||||||
|
|
||||||
function quoteId($name)
|
function quoteId($name)
|
||||||
|
@ -53,7 +90,7 @@ class DatabaseMysql
|
||||||
{
|
{
|
||||||
if ($value === NULL)
|
if ($value === NULL)
|
||||||
return "NULL";
|
return "NULL";
|
||||||
return "'" . $this->link->real_escape_string($s) . "'";
|
return "'" . $this->link->real_escape_string($value) . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
function query($sql, $fetchMode = MYSQLI_STORE_RESULT)
|
function query($sql, $fetchMode = MYSQLI_STORE_RESULT)
|
||||||
|
@ -182,7 +219,7 @@ class DatabaseMysql
|
||||||
{
|
{
|
||||||
if (is_array($v))
|
if (is_array($v))
|
||||||
{
|
{
|
||||||
$join = substr(strtolower($v[0]), 0, 4);
|
$join = strtolower(substr($v[0], 0, 4));
|
||||||
if ($join == 'righ')
|
if ($join == 'righ')
|
||||||
$join = 'RIGHT';
|
$join = 'RIGHT';
|
||||||
elseif ($join == 'left')
|
elseif ($join == 'left')
|
||||||
|
@ -326,6 +363,11 @@ class DatabaseMysql
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insert_id()
|
||||||
|
{
|
||||||
|
return $this->link->insert_id;
|
||||||
|
}
|
||||||
|
|
||||||
function update($table, $rows, $where = NULL, $options = NULL)
|
function update($table, $rows, $where = NULL, $options = NULL)
|
||||||
{
|
{
|
||||||
if (!$rows)
|
if (!$rows)
|
||||||
|
|
Loading…
Reference in New Issue