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);
答案 0 :(得分: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));
和上面的评论者一样,不要手工构建查询 - 使用上面的参数化查询。