1
CREATE OR REPLACE FUNCTION adduser(fn character varying,ln character varying,cit character varying,i integer,id integer)
  RETURNS void AS
$BODY$
        BEGIN                
    update tabtow set fname=fn,lname=ln,city=cit,phnum=i where phnum=id;
    select * from tabtow;
        END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION increment(integer)
  OWNER TO postgres;

这是我的函数,我如何在 PHP 中调用它?

我正在尝试这样,但它不起作用:

$sql = "update tabtow set fname = '$_REQUEST[fn]', lname = '$_REQUEST[ln]', city = '$_REQUEST[ci]', phnum = $_REQUEST[phnum] where phnum = $_REQUEST[id1]";
$res = pg_query($sql);
4

1 回答 1

3

只需调用函数:

$sql = 'SELECT adduser($1,$2,$3,$4)';
$res = pg_prepare($dbconn, "my_query", $sql);
$res = pg_execute($dbconn, "my_query", array('a','b','c',1));

就像上面的评论者说的那样,不要手动构建您的查询 - 使用上面的参数化查询。

于 2012-10-12T15:15:55.680 回答