我的代码中出现以下错误
警告:pg_num_rows()预计在第52行/var/www/funcoes.php中给出1个参数0,
这是函数的代码:
function cadastrarFornecedor($nome){
$qry = "INSERT INTO public.fornecedor (nome) VALUES ('".$nome."')";
$result = pg_query($qry);
if(pg_num_rows() > 0){
return 1;
}
else{
return 0;
}
}
答案 0 :(得分:3)
pg_num_rows
将结果集变量作为参数。错误告诉您预期会有参数,但没有提供参数。
请参阅行动签名:int pg_num_rows ( resource $result )
其中,$ result:
由pg_query()返回的PostgreSQL查询结果资源, pg_query_params()或pg_execute()(以及其他)
因此,您的代码应将查询结果集传递给pg_num_rows
,如下例所示:
function cadastrarFornecedor($nome){
$qry = "INSERT INTO public.fornecedor (nome) VALUES ('".$nome."')";
$result = pg_query($qry);
if(pg_num_rows($result) > 0){
return 1;
} else{
return 0;
}
}
来源:http://www.php.net/manual/en/function.pg-num-rows.php
(请注意,如果您插入带有pg_num_rows
触发器的视图,带有分区触发器/规则的表等,DO INSTEAD
将返回零。)
答案 1 :(得分:-2)
警告:pg_num_rows()在第52行/var/www/funcoes.php中给出正好1个参数,0
错误不言而喻
function cadastrarFornecedor($nome){
$qry = "INSERT INTO public.fornecedor (nome) VALUES ('" . $nome . "')";
$result = pg_query($qry);
if (pg_num_rows($result) > 0) {
return 1;
}
else {
return 0;
}
}