我是数据库管理的新手,但我需要将 Debian 4.0 32 位上的一个 Web 服务器迁移到 Debian Wheezy (7.6) 64 位并且遇到一些我无法使用 postgresql 和 php 修复的问题。
旧的 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 );
?>
最佳答案
您不能对整数使用 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 '%'
呢?这是荒谬的。修复您的代码生成,这样您就不会那样做。
关于php - pg_query() : Query failed: ERROR: operator does not exist: integer ~~ unknown\n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25528780/