pg_query():查询失败:ERROR:运算符不存在:整数~~ unknown \ n

时间:2014-08-27 13:41:36

标签: php apache postgresql

我是数据库管理的新手,但我需要将Debian 4.0 32bit上的一个Web服务器迁移到Debian Wheezy(7.6)64位,并且遇到一些麻烦,我无法修复postgresql和php。 / p>

旧的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 );
?>

1 个答案:

答案 0 :(得分:6)

您不能对整数使用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 '%'?这是荒谬的。修复代码生成,这样就不会那样做了。