mysql 存储过程的问题

很文博客hinwi.com 数据库评论165字数 2487阅读模式
广告也精彩

最近我接触了一本php 与 mysql,老外写的一本书,书中有个tshirtshop网店代码,其中操作数据库的大多用的是mysql存储过程
一开始用phpMyAdmin来执行,后来出现一堆错误,后来去掉了begin,end之后可以正常执行,但要执行存储过程,在phpMyAdmn中不行,而在mysql命令行文本框中就可以。

接下来又遇到更难的问题,在存储过程中加入预处理语句,更不行了,在mysql命令行文本框下执行同样,下面的运行记录,给大家参考,能否有高手来帮助。文章源自很文博客https://www.hinwi.com/很文博客-https://www.hinwi.com/52257.html

  1. mysql> CREATE PROCEDURE catalog_get_products_in_category(
  2. -> IN inCategoryId INT, IN inShortProductDescriptionLength INT,
  3. -> IN inProductsPerPage INT, IN inStartItem INT)
  4. -> begin
  5. -> SELECT p.product_id, p.name,IF(LENGTH(p.description) <= inShortProductD
  6. escriptionLength, p.description,
  7. -> CONCAT(LEFT(p.description, inShortProductDescriptionLength),'...')) AS
  8. description, p.price, p.discounted_price, p.thumbnail
  9. -> FROM product p INNER JOIN product_category pc ON p.product_id = pc.pro
  10. duct_id
  11. -> WHERE pc.category_id = inCategoryId
  12. -> ORDER BY p.display DESC
  13. -> LIMIT inStartItem;inProductsPerPage;
  14. -> end$$
  15. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
  16. corresponds to your MySQL server version for the right syntax to use near 'inSta
  17. rtItem;inProductsPerPage;
  18. end' at line 10

//原本的存储过程语句
EATE PROCEDURE catalog_get_products_in_category(
IN inCategoryId INT, IN inShortProductDescriptionLength 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 = inShortProductDescriptionLength; SET @p2 = inShortProductDescriptionLength; 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 inShortProductDescriptionLength 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 = inShortProductDescriptionLength;
-> SET @p2 = inShortProductDescriptionLength;
-> 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文章源自很文博客https://www.hinwi.com/很文博客-https://www.hinwi.com/52257.html

上面有两个存储过程,一个不用预处理语句,一个用了预处理语句,文章源自很文博客https://www.hinwi.com/很文博客-https://www.hinwi.com/52257.html

之后,向作者发过邮件,没有答复,又给mysql官方发过邮件,同样没答复。现今只能求助诸位高人。文章源自很文博客https://www.hinwi.com/很文博客-https://www.hinwi.com/52257.html 文章源自很文博客https://www.hinwi.com/很文博客-https://www.hinwi.com/52257.html

工具:作品在线观看

女优:最新作品观看

中文:国语在线观看

weinxin
我的微信
扫一扫更精彩
大家的支持是我更新的动力!!!
 
广告也精彩
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证