this is my php code
<?php
$code='1,2,3';
$this->db->query("CALL SP_db(\"$code\"));
?>
if i var_dump($code)
i get this string(5) "1,2,3"
and this my stored procedure code
CREATE DEFINER=`test`@`localhost` PROCEDURE `SP_db`(v_company varchar(10))
begin
select * from blabla where company_id in (v_company);
.
.
.
i use this code to insert some value into table the problem if i use this code,where i get v_company from php its not working
but if i try to fill the value it works
CREATE DEFINER=`test`@`localhost` PROCEDURE `SP_db`(v_company varchar(10))
begin
select * from blabla where company_id in (1,2,3);
but the value being sent by php is received by stored procedures, i try to save v_company value into table to make sure and it work
because the value from php entered into the table
so can someone tell where the code is wrong
When you pass '1,2,3' to your procedure, you get a string, and your query becomes
select * from blabla where company_id in ('1,2,3');
not
select * from blabla where company_id in (1,2,3);
You can use find_in_set
insted of in
select * from blabla where find_in_set(company_id, v_company);
but it will not use index so well, as in
does;
I think you are missing "
.
$this->db->query("CALL SP_db(\"$code\") ");
Or try this
$this->db->query("CALL SP_db('".$code."') ");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.