如何使mysqli与SQL语句中的DELIMITER一起使用? [英] How to get mysqli working with DELIMITERs in SQL statements?
问题描述
我正在使用mysqli,现在尝试从SQL代码片段(由MySQL Workbench生成)到数据库中获取视图.
I'm using mysqli and trying now to get a view from an SQL code snippet (generated by MySQL Workbench) into a database.
$query = <<<QUERY
DROP VIEW IF EXISTS `myview` ;
SHOW WARNINGS;
DROP TABLE IF EXISTS `myview`;
SHOW WARNINGS;
DELIMITER $$
CREATE OR REPLACE VIEW `myview` AS
...view definition...
$$
DELIMITER ;
;
SHOW WARNINGS;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
QUERY;
$result = mysqli_multi_query($dbConnection, $query);
这不起作用.没有错误,该语句似乎只是被忽略了.仅当删除定界符定义(行DELIMITER $$
,$$
和DELIMITER ;
)时,它才有效.
This doen't work. No errors, the statement seems just to be ignored. It only works, if I remove the delimiter definitions (lines DELIMITER $$
, $$
, and DELIMITER ;
).
为什么它不起作用?在传递给mysqli
函数和方法的SQL语句中如何/应该使用分隔符?
Why is it not working? What can/should I do to use delimiters in SQL statements passed to mysqli
functions and methods?
Thx
推荐答案
这是帮助我了解这一点的源... http ://zend-framework-community.634137.n4.nabble.com/Problems-changing-the-sql-end-of-statement-delimiter-tp2124060p2124276.html
This is the source that helped me understand this... http://zend-framework-community.634137.n4.nabble.com/Problems-changing-the-sql-end-of-statement-delimiter-tp2124060p2124276.html
DELIMITER不是实际的MySQL语句.
DELIMITER is not an actual MySQL Statement.
我相信这只是某些MySQL客户端已实现的功能,以帮助同时运送一堆sql语句.
I believe it is just something that some MySQL clients have implemented to help shipping a bunch of sql statements at the same time.
mysqli驱动程序未实现此功能.
所以,这应该工作.
$query = <<<QUERY
DROP VIEW IF EXISTS `myview` ;
SHOW WARNINGS;
DROP TABLE IF EXISTS `myview`;
SHOW WARNINGS;
CREATE OR REPLACE VIEW `myview` AS
...view definition...
;
SHOW WARNINGS;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
QUERY;
$result = mysqli_multi_query($dbConnection, $query);
我遇到了相同的问题,使用相同的mysqli驱动程序,multi_query函数(在创建过程时使用定界符),并从我的SQL中删除了 DELIMITER .
I ran into the same problem, with the same mysqli driver, with multi_query function (using delimiters while creating procedures) and removing the DELIMITER from my SQL worked.
这篇关于如何使mysqli与SQL语句中的DELIMITER一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!