简体   繁体   中英

How to use strings from php array in postgresql query?

need help with using php variables in postgresql query. I am trying to make several queries to postgresql database using php array elements, but it does't work. Can anybody help?

// $nums array with strings like - "983458999893440"  

for ($i=0; $i<count($nums); $i++){  

 $tm = pg_escape_string($nums[$i]);  

 $sql = "SELECT SUM(sp.summ) FROM tk.sp_tran sp WHERE sp.long_pan ='{$tm}'";  

   $panSum = dbCon::conn($sql);//return result of pg_fetch_all();  

//Code above don't work  
//Code below is ok   

 $tm = pg_escape_string("983458999893440");  

 $sql = "SELECT SUM(sp.summ) FROM tk.sp_tran sp WHERE sp.long_pan ='{$tm}'";  

   $panSum = dbCon::conn($sql);//return result of pg_fetch_all();  

//Please help to understand what is wrong?   

I find a space symbol before first letter of the string in csv file. So code is ok. It is just my an inattention(((

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