Recently I have been familiar with a book written by a foreigner in php and mysql. The book contains a tshirtshop online shop code, in which mysql stored procedures are used to operate databases.
Recently I have been familiar with a book written by a foreigner in php and mysql. The book contains a tshirtshop online shop code, in which mysql stored procedures are used to operate databases.
PhpMyAdmin was used for execution at the beginning, and a bunch of errors occurred later. begin was removed and can be executed normally after the end, but the stored procedure cannot be executed in phpMyAdmn, in the mysql command line text box, you can.
Next, I encountered a more difficult problem. I added a preprocessing statement to the stored procedure, but it was even worse. I executed the same statement in the mysql command line text box. The following running records are for your reference, can someone help me.
The Code is as follows:
Mysql> create procedure catalog_get_products_in_category (
-> IN inCategoryId INT, IN inmo-productdescriptionlength INT,
-> IN inProductsPerPage INT, IN inStartItem INT)
-> Begin
-> SELECT p. product_id, p. name, IF (LENGTH (p. description) <= in1_productd
EscriptionLength, p. description,
-> CONCAT (LEFT (p. description, inmo-productdescriptionlength), '...')
Description, p. price, p. discounted_price, p. thumbnail
-> FROM product p inner join product_category pc ON p. product_id = pc. pro
Duct_id
-> WHERE pc. category_id = inCategoryId
-> Order by p. display DESC
-> LIMIT inStartItem; inProductsPerPage;
-> End $
ERROR 1064 (42000): 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 'insta
RtItem; inProductsPerPage;
End 'at line 10
// Original Stored Procedure statement
Eate procedure catalog_get_products_in_category (
IN inCategoryId INT, IN inner productdescriptionlength INT,
IN inProductsPerPage INT, IN inStartItem INT)
BEGIN
PREPARE statement FROM
"SELECT p. product_id, p. name, IF (LENGTH (p. description) <= ?, P. description,
CONCAT (LEFT (p. description ,?), '...') AS description, p. price, p. discounted_price, p. thumbnail
FROM product p inner join product_category pc ON p. product_id = pc. product_id
WHERE pc. category_id =?
Order by p. display DESC
LIMIT ?, ? ";
SET @ p1 = inmo-productdescriptionlength;
SET @ p2 = inmo-productdescriptionlength;
SET @ p3 = inCategoryId;
SET @ p4 = inStartItem;
SET @ p5 = inProductsPerPage;
EXECUTE statement USING @ p1, @ p2, @ p3, @ p4, @ p5;
END $
Mysql> delimiter $
Mysql> create procedure catalog_get_products_in_category (
-> IN inCategoryId INT, IN inmo-productdescriptionlength INT,
-> IN inProductsPerPage INT, IN inStartItem INT)
-> BEGIN
-> PREPARE statement FROM
-> "SELECT p. product_id, p. name, IF (LENGTH (p. description) <= ?, P. descript
Ion,
"> CONCAT (LEFT (p. description ,?), '...') AS description, p. price, p. disco
Unted_price, p. thumbnail
"> FROM product p inner join product_category pc ON p. product_id = pc. pro
Duct_id
"> WHERE pc. category_id =?
"> Order by p. display DESC
"> LIMIT ?, ? ";
-> SET @ p1 = inmo-productdescriptionlength;
-> SET @ p2 = inmo-productdescriptionlength;
-> SET @ p3 = inCategoryId;
-> SET @ p4 = inStartItem;
-> SET @ p5 = inProductsPerPage;
-> EXECUTE statement USING @ p1, @ p2, @ p3, @ p4, @ p5;
-> END $
ERROR 1314 (0A000): PREPARE is not allowed in stored procedures
There are two stored procedures, one with no preprocessing statement and the other with preprocessing statement,
Afterwards, I sent an email to the author, without a reply, and sent an email to the mysql official website. Currently, you can only seek help from senior personnel.