Jump to content

Creating a stored procedure using PHP


Enormity

Recommended Posts

I am trying to make a  setup file for a website I'm developing, and am having the database tables and stored procedures created automatically.  However, I'm having issue getting the stored procedures to be created.  Here is my code:

$db->Q("
DELIMITER $$
CREATE PROCEDURE `Database`.`Procedure_Name`(in sp_uid mediumint(20) unsigned, in sp_user varchar(15), in sp_pass varchar(20), in sp_email varchar(30))
BEGIN 
	Insert Into Table Values (sp_uid, sp_user, md5(sp_pass), sp_email, '1', '1', '0');
	Select true;
END$$
");

 

Assume that the "$db->Q()" works just fine, as I'm having issues no where else with it.  This automatically connects to the database and runs a query with whatever is inside the "()".  The tables are being created just fine, but no stored procedures are being created.  I've tried everything I can think of, and googled my question many different ways without finding an answer or work-through.  Does anyone know what I am doing wrong?

 

Thanks in advance.

Link to comment
Share on other sites

That must be a custom DB package, does it have error handling at all? If not you should still be able to catch the error with mysql_error(), assuming it's MySQL and not MySQLi (which you'd just use the equivalent for). Find out the error message..

Link to comment
Share on other sites

Yes, but the error is of no help.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$ CREATE PROCEDURE `U_C_D`.`Admin_Login_Create`(in sp_uid mediumin' at line 1

Link to comment
Share on other sites

Well, I ended up fixing it...  I just took out the delimiter...  I don't know why that would work, or why I didn't try that before.  The query looks like this now.

 

$db->Q("
   CREATE PROCEDURE `Database`.`Procedure_Name`(in sp_uid mediumint(20) unsigned, in sp_user varchar(15), in sp_pass varchar(20), in sp_email varchar(30))
   BEGIN
      Insert Into Table Values (sp_uid, sp_user, md5(sp_pass), sp_email, '1', '1', '0');
      Select true;
   END
");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.