大家好我想尝试使用php创建一个开放式购物车应用程序,我想连接一个sql server数据库而不是mysql数据库,并且我遇到以下错误:Call to undefined function DB\mssql_connect()
,我设置我的配置文件:
<?php
// HTTP
define('HTTP_SERVER', 'http://localhost/restaurant/admin/');
define('HTTP_CATALOG', 'http://localhost/restaurant/');
// HTTPS
define('HTTPS_SERVER', 'http://localhost/restaurant/admin/');
define('HTTPS_CATALOG', 'http://localhost/restaurant/');
// DIR
define('DIR_APPLICATION', 'E:/my work/wamp/www/restaurant/admin/');
define('DIR_SYSTEM', 'E:/my work/wamp/www/restaurant/system/');
define('DIR_IMAGE', 'E:/my work/wamp/www/restaurant/image/');
define('DIR_LANGUAGE', 'E:/my work/wamp/www/restaurant/admin/language/');
define('DIR_TEMPLATE', 'E:/my work/wamp/www/restaurant/admin/view/template/');
define('DIR_CONFIG', 'E:/my work/wamp/www/restaurant/system/config/');
define('DIR_CACHE', 'E:/my work/wamp/www/restaurant/system/storage/cache/');
define('DIR_DOWNLOAD', 'E:/my work/wamp/www/restaurant/system/storage/download/');
define('DIR_LOGS', 'E:/my work/wamp/www/restaurant/system/storage/logs/');
define('DIR_MODIFICATION', 'E:/my work/wamp/www/restaurant/system/storage/modification/');
define('DIR_UPLOAD', 'E:/my work/wamp/www/restaurant/system/storage/upload/');
define('DIR_CATALOG', 'E:/my work/wamp/www/restaurant/catalog/');
// DB
define('DB_DRIVER', 'mssql');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'AndlusMarket');
define('DB_PORT', '1433');
define('DB_PREFIX', 'oc_');
我搜索了很多解决方案,但很多人说很难有人帮助我吗?
答案 0 :(得分:2)
我认为您应该更新您的问题并具体针对opencart版本。没问题,所以在较新的版本中,内置了一个名为mpdo的类。所以你需要
define('DB_DRIVER', 'mpdo');
try {
$this->connection = new \PDO("mysql:host=" . $hostname . ";port=" . $port . ";dbname=" . $database, $username, $password, array(\PDO::ATTR_PERSISTENT => true));
} catch(\PDOException $e) {
throw new \Exception('Failed to connect to database. Reason: \'' . $e->getMessage() . '\'');
}
$this->connection->exec("SET NAMES 'utf8'");
$this->connection->exec("SET CHARACTER SET utf8");
$this->connection->exec("SET CHARACTER_SET_CONNECTION=utf8");
$this->connection->exec("SET SQL_MODE = ''");
将其替换为
try {
$this->connection = new \PDO("sqlsrv:Server=" . $hostname . ";port=" . $port . ";Database=" . $database, $username, $password);
} catch(\PDOException $e) {
throw new \Exception('Failed to connect to database. Reason: \'' . $e->getMessage() . '\'');
}
$this->connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
答案 1 :(得分:0)
您需要使用PDO连接OpenCart
我为mysql创建了PDO类,您可以从OpenCart PDO
下载你需要将这个课程放在
中{your opencart folder} > system >database > pdo.php
使用pdo.php创建类文件名
只需用DBpdo替换类名
只需替换
中的字符串即可$this->params->connstr = "sqlsrv:Server={$host};dbname={$name};charset={$charset}";
您需要更改config.php
define('DB_DRIVER', 'PDO');
你可以替换
$this->dbh->exec($this->options['PDO::MYSQL_ATTR_INIT_COMMAND']);
与
$this->dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );