For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > October 2006 > error in calling a stored procedure in php









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author error in calling a stored procedure in php
Gayatri

2006-10-31, 7:57 am

i've a sql query as follows:

SELECT tb1.col1,tb2.col1,tb3.col1 FROM tb1,tb2,tb3 where
tb1.col1=tb2.col2 AND tb3.col3=tb2.col3 AND tb2.col4 BETWEEN 4 AND 5
AND tb2.col5 BETWEEN 6 AND 7;

if I run the above query thru php it works, but if i try to call a
procedure for above query as shown below it thrws error
ERROR 1064 (42000): the right syntax to use near 'tb1.col2
<?
$wherestr = "tb2.col4 BETWEEN 4 AND 5 AND tb2.col5 BETWEEN 6 AND 7";
CALL proc4($wherestr);

?>
Procedure#=>

DELIMITER $$

DROP PROCEDURE IF EXISTS `midas`.`sp_dm_domain_keyword_mapping`$$
CREATE DEFINER=`oteuser`@`%` PROCEDURE `sp_dm_domain_keyword_mapping`(
whereval varchar(500))
BEGIN

set @whereval = whereval;


set @sql1 = CONCAT('SELECT tb1.col1,tb2.col1,tb3.col1 FROM tb1,tb2,tb3
where tb1.col1=tb2.col2 AND tb3.col3=tb2.col3 AND ',@whereval);
PREPARE stmt FROM @sql1;

EXECUTE stmt using @whereval;
DEALLOCATE PREPARE stmt;


END$$

DELIMITER ;

what is the error in above code?

Jerry Stuckle

2006-10-31, 7:57 am

Gayatri wrote:
> i've a sql query as follows:
>
> SELECT tb1.col1,tb2.col1,tb3.col1 FROM tb1,tb2,tb3 where
> tb1.col1=tb2.col2 AND tb3.col3=tb2.col3 AND tb2.col4 BETWEEN 4 AND 5
> AND tb2.col5 BETWEEN 6 AND 7;
>
> if I run the above query thru php it works, but if i try to call a
> procedure for above query as shown below it thrws error
> ERROR 1064 (42000): the right syntax to use near 'tb1.col2
> <?
> $wherestr = "tb2.col4 BETWEEN 4 AND 5 AND tb2.col5 BETWEEN 6 AND 7";
> CALL proc4($wherestr);
>
> ?>
> Procedure#=>
>
> DELIMITER $$
>
> DROP PROCEDURE IF EXISTS `midas`.`sp_dm_domain_keyword_mapping`$$
> CREATE DEFINER=`oteuser`@`%` PROCEDURE `sp_dm_domain_keyword_mapping`(
> whereval varchar(500))
> BEGIN
>
> set @whereval = whereval;
>
>
> set @sql1 = CONCAT('SELECT tb1.col1,tb2.col1,tb3.col1 FROM tb1,tb2,tb3
> where tb1.col1=tb2.col2 AND tb3.col3=tb2.col3 AND ',@whereval);
> PREPARE stmt FROM @sql1;
>
> EXECUTE stmt using @whereval;
> DEALLOCATE PREPARE stmt;
>
>
> END$$
>
> DELIMITER ;
>
> what is the error in above code?
>


Since this is a sql problem, I'd recommend you ask in a SQL newsgroup -
or at least one related to your database.

You'll get better answers.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com