2014-08-27 70 views
0

我是数据库管理新手,但我需要将Debian 4.0 32bit上的一个Web服务器迁移到Debian Wheezy(7.6)64bit并有一些麻烦,我无法修复postgresql和PHP。pg_query():查询失败:错误:运算符不存在:整数~~未知 n

旧postgres是8.1新是9.3。

下面是Apache日志错误:

PHP Warning: pg_query(): Query failed: ERROR: operator does not exist: integer ~~ 
unknown\nLINE 1: SELECT * from sel_v_pc() WHERE pc_nomer LIKE '%' AND pccat_n...\n 
^\nHINT: No operator matches the given name and argument type(s). 
You might need to add explicit type casts. in /var/www/itweb/register/pc/pc.php on line 66 

这里是源:

 $default_sort = 'pc_nomer'; 
$allowed_order = array ('pc_nomer', 'structure_name', 'corpus_name', 'office_name', 'cputype_name', 'monitor_nomer', 'employee_name1', 'employee_name3'); 

if (!isset ($_GET['order']) || !in_array ($_GET['order'], $allowed_order)) { 
    $order = $default_sort; 
} else { 
    $order = $_GET['order']; 
} 
if (!isset ($_GET['find'])) { 
$query = "SELECT * from sel_v_pc() ORDER BY $order, pc_nomer";} 
// ÒÚÐÑÅÍÅ 
else { 
    for($j = 0; $j < sizeof($_GET['finom']); $j++) 
     {$finom = $_GET['finom'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fpccat']); $j++) 
     {$fpccat = $_GET['fpccat'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fstruct']); $j++) 
     {$fstruct = $_GET['fstruct'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fustruct']); $j++) 
     {$fustruct = $_GET['fustruct'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fcorpus']); $j++) 
     {$fcorpus = $_GET['fcorpus'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['foffice']); $j++) 
     {$foffice = $_GET['foffice'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fotype']); $j++) 
     {$fotype = $_GET['fotype'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fcpu']); $j++) 
     {$fcpu = $_GET['fcpu'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fcpufrecq']); $j++) 
     {$fcpufrecq = $_GET['fcpufrecq'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fram']); $j++) 
     {$fram = $_GET['fram'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fhdd']); $j++) 
     {$fhdd = $_GET['fhdd'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['fcd']); $j++) 
     {$fcd = $_GET['fcd'][$j]; 
     }  
    for($j = 0; $j < sizeof($_GET['fempl']); $j++) 
     {$fempl = $_GET['fempl'][$j]; 
     } 
    for($j = 0; $j < sizeof($_GET['orderby']); $j++) 
     {$forder = $_GET['orderby'][$j]; 
     }  
    $query = "SELECT * from sel_v_pc() WHERE pc_nomer LIKE '$finom' AND pccat_name LIKE '$fpccat' AND structure_id LIKE '$fstruct' AND understructure_id LIKE '$fustruct' AND corpus_name LIKE '$fcorpus' AND office_name LIKE '$foffice' AND officetype_sign LIKE '$fotype' AND employee_id LIKE '$fempl' AND cputype_id LIKE '$fcpu' AND cpufrecq_ghz LIKE '$fcpufrecq' AND ram_mb LIKE '$fram' AND hdd_gb LIKE '$fhdd' AND cd_type LIKE '$fcd' ORDER BY $forder, pc_nomer";} 

    $result = pg_query ($query); 

    $total = pg_num_rows ($result); 
?> 

回答

4

你不能在一个整数使用LIKE

regress=# select 42 like '4%'; 
ERROR: operator does not exist: integer ~~ unknown 
LINE 1: select 42 like '4%'; 

您必须转换左操作数为文本,如果你真的想要模式匹配的整数

regress=# select 42::text like '4%'; 
?column? 
---------- 
t 
(1 row) 

,但它几乎总是更好地使用数学比较来代替。

在审查问题后编辑:为什么地球上你会不会写LIKE '%'?这是无稽之谈。修复你的代码生成,所以你不这样做。

相关问题