Creating stored procedure for MySQL db using PHP script
Posted: Wed Jan 13, 2010 2:22 pm
Hi
I am not able to create stored procedure within MySQL database using PHP script.
Script bellow creates succesfully new db then it switches to it then creates table with no problems so far but then it struggles with creating stored procedure in the db. It doesn't give me any error message.
When I paste the $command echoed to the MySQL shell it ends up with "_>" and does nothing.
I tried to Google it with no success at all.
I also tried to change the DELIMITER value with no luck. If anybody tackled this problem previously or knows how to solve my problem I will really appreciate it.
My project is going to be Open Source. I work on that code because I do like scripting. Now I am stuck.
Thank you for any suggestions.
Script that doesn't finish creating stored procedures and gives no error messages. It does create the new database and new table only:
I am not able to create stored procedure within MySQL database using PHP script.
Script bellow creates succesfully new db then it switches to it then creates table with no problems so far but then it struggles with creating stored procedure in the db. It doesn't give me any error message.
When I paste the $command echoed to the MySQL shell it ends up with "_>" and does nothing.
I tried to Google it with no success at all.
I also tried to change the DELIMITER value with no luck. If anybody tackled this problem previously or knows how to solve my problem I will really appreciate it.
My project is going to be Open Source. I work on that code because I do like scripting. Now I am stuck.
Thank you for any suggestions.
Script that doesn't finish creating stored procedures and gives no error messages. It does create the new database and new table only:
Code: Select all
.
.
.
$db_server = "localhost";
$db_user = "root";
$db_password = "l0ngWaY";
$db_name = "test03";
$command = "
CREATE DATABASE $db_name;
USE $db_name;
CREATE TABLE tags (
id int(11) NOT NULL auto_increment,
tag text NOT NULL default 'not categorized',
PRIMARY KEY (id),
FULLTEXT KEY tag (tag)
) ENGINE=MyISAM ;
DELIMITER //
CREATE PROCEDURE tag_new(
IN par_tag text
)
BEGIN
INSERT INTO tags
(
tag,
count
)
VALUES
(
par_tag,
1
);
END
//
CREATE PROCEDURE tag_update(
IN par_id INT,
IN par_tag text
)
BEGIN
UPDATE tags
SET
tag = par_tag
WHERE
id = par_id;
END
//
DELIMITER ;
";
echo $command;
$connection = @mysql_connect( $db_server, $db_user , $db_password);
$result = mysql_query($command, $connection);
mysql_close($connection);
.
.
.