[+] Add native MySQLi support
This commit is contained in:
1 parent
65c5a8f35c
commit
d84373e4d3
4 files changed
+183
-3
No files matched your search
Vendored
+2
@@ -76,6 +76,8 @@
|
|||||||
'DateRange' => 'override/classes/DateRange.php',
|
'DateRange' => 'override/classes/DateRange.php',
|
||||||
'DbCore' => 'classes/Db.php',
|
'DbCore' => 'classes/Db.php',
|
||||||
'Db' => 'override/classes/Db.php',
|
'Db' => 'override/classes/Db.php',
|
||||||
|
'DbMySQLiCore' => 'classes/DbMySQLi.php',
|
||||||
|
'DbMySQLi' => 'override/classes/DbMySQLi.php',
|
||||||
'DeliveryCore' => 'classes/Delivery.php',
|
'DeliveryCore' => 'classes/Delivery.php',
|
||||||
'Delivery' => 'override/classes/Delivery.php',
|
'Delivery' => 'override/classes/Delivery.php',
|
||||||
'DiscountCore' => 'classes/Discount.php',
|
'DiscountCore' => 'classes/Discount.php',
|
||||||
|
|||||||
+3
-3
@@ -170,9 +170,9 @@ abstract class DbCore
|
|||||||
|
|
||||||
if (!isset(self::$_instance[$idServer]))
|
if (!isset(self::$_instance[$idServer]))
|
||||||
{
|
{
|
||||||
$class = _DB_TYPE_;
|
$class = 'MySQL';
|
||||||
if (!class_exists($class))
|
if (class_exists('mysqli', false))
|
||||||
$class = 'MySQL';
|
$class = 'DbMySQLi';
|
||||||
self::$_instance[$idServer] = new $class(self::$_servers[$idServer]['server'], self::$_servers[$idServer]['user'], self::$_servers[$idServer]['password'], self::$_servers[$idServer]['database']);
|
self::$_instance[$idServer] = new $class(self::$_servers[$idServer]['server'], self::$_servers[$idServer]['user'], self::$_servers[$idServer]['password'], self::$_servers[$idServer]['database']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Open Software License (OSL 3.0)
|
||||||
|
* that is bundled with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://opensource.org/licenses/osl-3.0.php
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@prestashop.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* DISCLAIMER
|
||||||
|
*
|
||||||
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||||
|
* versions in the future. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision$
|
||||||
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
class DbMySQLiCore extends Db
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see DbCore::connect()
|
||||||
|
*/
|
||||||
|
public function connect()
|
||||||
|
{
|
||||||
|
$this->_link = new mysqli($this->_server, $this->_user, $this->_password, $this->_database);
|
||||||
|
|
||||||
|
// Do not use object way for error because this work bad before PHP 5.2.9
|
||||||
|
if (mysqli_connect_error())
|
||||||
|
die(Tools::displayError('Link to database cannot be established : '.mysqli_connect_error()));
|
||||||
|
|
||||||
|
// UTF-8 support
|
||||||
|
if (!$this->_link->query('SET NAMES \'utf8\''))
|
||||||
|
die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
|
||||||
|
|
||||||
|
return $this->_link;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::disconnect()
|
||||||
|
*/
|
||||||
|
public function disconnect()
|
||||||
|
{
|
||||||
|
$this->_link->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::_query()
|
||||||
|
*/
|
||||||
|
protected function _query($sql)
|
||||||
|
{
|
||||||
|
return $this->_link->query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::nextRow()
|
||||||
|
*/
|
||||||
|
public function nextRow($result = false)
|
||||||
|
{
|
||||||
|
if (!$result)
|
||||||
|
$result = $this->_result;
|
||||||
|
return $result->fetch_assoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::_numRows()
|
||||||
|
*/
|
||||||
|
protected function _numRows($result)
|
||||||
|
{
|
||||||
|
return $result->num_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::Insert_ID()
|
||||||
|
*/
|
||||||
|
public function Insert_ID()
|
||||||
|
{
|
||||||
|
return $this->_link->insert_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::Affected_Rows()
|
||||||
|
*/
|
||||||
|
public function Affected_Rows()
|
||||||
|
{
|
||||||
|
return $this->_link->affected_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::getMsgError()
|
||||||
|
*/
|
||||||
|
public function getMsgError($query = false)
|
||||||
|
{
|
||||||
|
return $this->_link->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::getNumberError()
|
||||||
|
*/
|
||||||
|
public function getNumberError()
|
||||||
|
{
|
||||||
|
return $this->_link->errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::getVersion()
|
||||||
|
*/
|
||||||
|
public function getVersion()
|
||||||
|
{
|
||||||
|
return $this->getValue('SELECT VERSION()');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::_escape()
|
||||||
|
*/
|
||||||
|
public function _escape($str)
|
||||||
|
{
|
||||||
|
return $this->_link->real_escape_string($str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DbCore::set_db()
|
||||||
|
*/
|
||||||
|
public function set_db($db_name)
|
||||||
|
{
|
||||||
|
return $this->_link->query('USE '.pSQL($db_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tryToConnect return 0 if the connection succeed and the database can be selected.
|
||||||
|
* @since 1.4.4.0, the parameter $newDbLink (default true) has been added.
|
||||||
|
*
|
||||||
|
* @param string $server mysql server name
|
||||||
|
* @param string $user mysql user
|
||||||
|
* @param string $pwd mysql user password
|
||||||
|
* @param string $db mysql database name
|
||||||
|
* @param boolean $newDbLink Param not used in this class
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
static public function tryToConnect($server, $user, $pwd, $db, $newDbLink = true)
|
||||||
|
{
|
||||||
|
$link = new mysqli($server, $user, $password, $db);
|
||||||
|
|
||||||
|
// Do not use object way for error because this work bad before PHP 5.2.9
|
||||||
|
if (mysqli_connect_error())
|
||||||
|
return 1;
|
||||||
|
$link->close();
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// UTF-8 support
|
||||||
|
if (!$this->_link->query('SET NAMES \'utf8\''))
|
||||||
|
die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function tryUTF8($server, $user, $pwd)
|
||||||
|
{
|
||||||
|
$link = new mysqli($server, $user, $password, $db);
|
||||||
|
$ret = $link->query("SET NAMES 'UTF8'");
|
||||||
|
$link->close();
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DbMySQLi extends DbMySQLiCore
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user