Convertir Procedimiento en comando sql
Publicado por Ansermo (1 intervención) el 13/11/2010 18:12:03
Saludo, hace poco termine una pagina autodidacta que utiliza procedimiento almacenado en su base de datos (procedure Stored) sin embargo no he encontrado hosting gratuito que ofresca el servicio de procedimiento almacenado en su base de datos, por lo tanto he decidido cambiar los procedimientos almacenados a sentencia sql, la mayorias han funcionado sin embargo tengo problema con la sgte.
(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.price2, p.discounted_price2, p.price3, p.discounted_price3, p.price4,
p.discounted_price4, p.price5, p.discounted_price5, p.price6, p.discounted_price6, 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)
LA CUAL ES CONVERTIDO EN LA SIGUIENTE SENTENCIA SQL
$sql =
'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.price2, p.discounted_price2, p.price3, p.discounted_price3, p.price4,
p.discounted_price4, p.price5, p.discounted_price5, p.price6, p.discounted_price6, 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';
sin embargo me presenta el siguiente error "Parse error: parse error in C:\metalarts\business\catalog.php on line 168" la lineas 168 es dice "CONCAT(LEFT(p.description, ?), '...')) AS description," imagino que es por la comilla simple pero es la que recomienda el manual para encerrar string. necesito su ayuda por favor.
"
(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.price2, p.discounted_price2, p.price3, p.discounted_price3, p.price4,
p.discounted_price4, p.price5, p.discounted_price5, p.price6, p.discounted_price6, 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)
LA CUAL ES CONVERTIDO EN LA SIGUIENTE SENTENCIA SQL
$sql =
'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.price2, p.discounted_price2, p.price3, p.discounted_price3, p.price4,
p.discounted_price4, p.price5, p.discounted_price5, p.price6, p.discounted_price6, 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';
sin embargo me presenta el siguiente error "Parse error: parse error in C:\metalarts\business\catalog.php on line 168" la lineas 168 es dice "CONCAT(LEFT(p.description, ?), '...')) AS description," imagino que es por la comilla simple pero es la que recomienda el manual para encerrar string. necesito su ayuda por favor.
"
Valora esta pregunta


0