使用MySQLi和Zend_DB的未准备查询
问题描述:
由于我的服务器PDO版本中存在一个错误,我已切换到使用MySQLi。但是,这带来另一个问题,因为Zend_DBMySQLi adaptor没有执行功能。 (Zend PDO adaptor did),这意味着我不能执行一个sql脚本。 (包含DROP TABLE和CREATE TABLE查询的加载)。使用MySQLi和Zend_DB的未准备查询
那么,我可能只是这样做:
$sqlQuery = file_get_contents('schema.sql');
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->exec($sqlQuery);
我无法找到一个方法来做到这一点使用Zend库MySQLi适配器。有任何想法吗?
答
尝试:
$sqlQuery = file_get_contents('schema.sql');
$adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
$mysqli = $adapter->getConnection(); // i think the returns the Mysqli Instance directly...
$mysqli->multi_query($sqlQuery);
答
这是我做过什么
$bootstrap = $application->getBootstrap();
$bootstrap->bootstrap(‘db’);
$config = $bootstrap->getResource(‘db’)->getConfig();
$runCommand = “mysql -h “.$config["host"].” -P “.$config["port"].” -u’”.$config["username"].”‘ -p’”.$config["password"].”‘ “.$config["dbname"].” < “.dirname(__FILE__) . ‘/schema.mysql.sql’;
echo $runCommand;
system($runCommand);
更多信息: http://www.unexpectedit.com/zend-php/zend-db-exec-a-sql-file