Php postgresql error, prepared statement already exists -
am getting error of prepared statement "my_query7" exists, call function each time user tries update table leader_info in database, have gone through documentation pg_prepare , don't understand meant should run once. code snippets of help. thanks.
function add_leader_country($user_id,$l_country) { global $connection; $query = pg_prepare($connection,"my_query7","update leader_info set l_country = $1 user_id = $2 , status < 9"); $result = pg_execute($connection,"my_query7",array($l_country,$user_id)); if(!$result) { echo pg_last_error($connection); } else { echo "records created successfully\n"; } $row = pg_affected_rows($result); return $row; }
prepare execute not permit duplicate naming, error. query should prepared once, example, in cycle preparation state must set out of , execution in for.
$result=$pg_prepare($connection,"my_query7",$query); for($id=1;$id<3;$id++){ $result=pg_execute($connection,"my_query7",array($l_country,$user_id)); ... }
in case using functio use prepare , execute multiple times it's problem.
what trying accomplish function dispatches more code calling function. way might able you.
if want use functions use method
exemple https://secure.php.net
<?php function requesttodb($connection,$request){ if(!$result=pg_query($connection,$request)){ return false; } $combined=array(); while ($row = pg_fetch_assoc($result)) { $combined[]=$row; } return $combined; } ?> <?php $conn = pg_pconnect("dbname=mydatabase"); $results=requesttodb($connect,"select * mytable"); //you can access "cell" of table this: $rownumber=0; $columname="mycolumn"; $mycell=$results[$rownumber][$columname]; var_dump($mycell);
if whant use preaper , execute functions try create function creates preparations once in session. not forget give different names same error not occur. tried find of genre , did not find. if find form presented here others learn. if in meantime find way present it.
Comments
Post a Comment