开发者

A non-prepared query using MySQLi and Zend_DB

开发者 https://www.devze.com 2022-12-15 12:03 出处:网络
Due to a bug in my servers PDO version, I have switc开发者_如何学编程hed to using MySQLi. However, this presents another problem, as the Zend_DB MySQLi adaptor doesn\'t have an exec function. (The Zen

Due to a bug in my servers PDO version, I have switc开发者_如何学编程hed to using MySQLi. However, this presents another problem, as the Zend_DB MySQLi adaptor doesn't have an exec function. (The Zend PDO adaptor did), which means I can't execute a sql script. (Containing a load of DROP TABLE and CREATE TABLE queries).

So where I could just do:

$sqlQuery = file_get_contents('schema.sql');
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->exec($sqlQuery);

I can't find a way to do this using the Zend MySQLi Adaptor. Any ideas?


Try:

$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);


This is what I did

$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);

More info: http://www.unexpectedit.com/zend-php/zend-db-exec-a-sql-file

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号