I have a problem deploying stored procedures on a MySQL database from
a PHP-script. What I have done is to write a whole SQL-script inside
HEREDOC syntax, then call the multi_query() function from the mysqli
package. The thing is, is that the tables get installed but not the
procedures. The SQL-script works just perfect when I run it from the
MySQL Query Browser. The platform I am using is WAMP5 Version 1.7.3
Please could someone help me?
The script:
<?php
$query =<<<EOQ
DROP DATABASE IF EXISTS mydb;
CREATE DATABASE mydb;
USE mydb;
CREATE TABLE IF NOT EXISTS `bt_Languages` (
LanguageID INTEGER (10) NOT NULL AUTO_INCREMENT,
Name VARCHAR (50) NOT NULL,
Code VARCHAR (2) NOT NULL UNIQUE,
PRIMARY KEY (LanguageID)
/* And another bunch of tables */
DELIMITER |
CREATE PROCEDURE AddLanguage (IN lang VARCHAR (50), IN code VARCHAR
(2))
BEGIN
INSERT INTO bt_Languages (Name, Code) VALUES (lang, code);
END;
|
DELIMITER ;
/* And another bunch of procedures */
call AddLanguage('Svenska', 'sv');
EOQ;
$db = new mysqli("localhost", "root", "", "");
$db -> multi_query($query);
$db -> multi_query('CALL AddLanguage("Svenska", "sv");');
$db -> close();
?>
http://us.php.net/manual/en/function.mysqli-multi-query.php
Might be of help.