简体   繁体   中英

How to pass php variable as value in store procedure call in sql query?

I am not getting any results while passing the values intot the stores procuder I have the code below

<?php

     $a="26456";

     $result3=mysql_query('CALL getItemStock($a)');
     $row = mysql_fetch_array($result3);
?>

Try this:

    $result3=mysql_query('CALL getItemStock('.$a.')');

or

    $result3=mysql_query("CALL getItemStock($a)");

UPDATE:

If the parameter defined as string then you need to enclose it with quotes as well. For example:

    $a = 'I am String';
    $result3=mysql_query("CALL getItemStock('$a')");

However, if the parameter defined as number, then no quotation required.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM