How to get mysqli working with DELIMITERs in SQL statements?

后端 未结 1 1356
眼角桃花
眼角桃花 2021-01-06 17:48

I\'m using mysqli and trying now to get a view from an SQL code snippet (generated by MySQL Workbench) into a database.

$query = <<

        
相关标签:
1条回答
  • 2021-01-06 18:09

    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 is not an actual MySQL Statement.

    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 driver does not implement this functionality.

    So, this should work.

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

    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.

    0 讨论(0)
提交回复
热议问题