Createing stored procedures on MySQL from within PHP5

23 views
Skip to first unread message

krillzip

unread,
Oct 26, 2007, 6:32:47 PM10/26/07
to Professional PHP Developers
Hi!

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

?>

Novak

unread,
Oct 30, 2007, 4:05:03 PM10/30/07
to Professional PHP Developers
See the User Contributed Notes on this page:

http://us.php.net/manual/en/function.mysqli-multi-query.php

Might be of help.

Reply all
Reply to author
Forward
0 new messages