简体   繁体   English

如何在PostgreSQL查询中使用PHP数组中的字符串?

[英]How to use strings from php array in postgresql query?

need help with using php variables in postgresql query. 需要在postgresql查询中使用php变量的帮助。 I am trying to make several queries to postgresql database using php array elements, but it does't work. 我正在尝试使用php数组元素对postgresql数据库进行几个查询,但是它不起作用。 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. 我在csv文件中的字符串的第一个字母之前找到了一个空格符号。 So code is ok. 这样代码就可以了。 It is just my an inattention((( 这只是我的疏忽(((

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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