問題描述
我正在從 PHP 讀取 TEXT 文件并嘗試從中執行命令,例如創建數據庫及其擁有的所有表和過程.我的代碼創建了表,但沒有創建文件中給出的存儲過程.
I am reading a TEXT file from PHP and trying to execute commands from it, like creating a DB and all the tables and procedures it has. My code creates the tables but does not create Stored Procedures given in the file.
DELIMITER $$
DROP PROCEDURE IF EXISTS `add_hits`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `add_hits`( In id varchar(255))
BEGIN
select hits into @hits from db_books where Book_ID = id;
update db_books set hits=@hits+1 where Book_ID = id;
END$$
PDO 沒有創建 SP,如何才能完成這項任務?我已經嘗試將所有代碼部分一起并逐行執行,但沒有任何效果.
我正在嘗試制作數據庫安裝程序腳本.
The PDO is not creating the SPs, how will be able to accomplish this task?
I have tried executing all the code part together and line by line, but nothing works.
I am trying to make a DB installer script.
推薦答案
好吧,PMA 幫我回答了我自己的這個問題.
為了克服這個問題,您需要刪除程序的分隔符部分,以便您的查詢變成:
Well, PMA Helped me with answering this Question of my own.
To overcome this you need to remove the delimiter part of the procedure, so that your queries become like:
DROP PROCEDURE IF EXISTS `add_hits`;
CREATE DEFINER=`root`@`localhost` PROCEDURE `add_hits`( In id varchar(255))
BEGIN
declare hits_bk int;
select hits into hits_bk from db_books where Book_ID = id;
update db_books set hits=hits_bk+1 where Book_ID = id;
END;
現在查詢將起作用.
感謝@Your Common Sense 和@RiggsFolly 的幫助.
Now the queries will work.
Thanks to @Your Common Sense and @RiggsFolly for helping out.
這篇關于在 PHP 中使用 PDO 創建存儲過程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!