I notice that these two ways of structuring a query with PHP PDO, both return the same data.
//prepare with $dbh->prepare
$w_ft = "36";
$sth = $dbh->prepare("SELECT * FROM main_products_common_dimensions WHERE w_ft = :w_ft");
$sth->bindParam(':w_ft', $theId, PDO::PARAM_INT);
$sth->execute();
$result = $sth->fetchAll(); //PHP array of data
//prepare with pg_prepare()
$result = pg_prepare($con, "my_query", 'SELECT * FROM main_products_common_dimensions WHERE w_ft = $1');
$result = pg_execute($con, "my_query", array("48")); //A query result resource on success or FALSE on failure.
while ($row = pg_fetch_assoc($result)){
echo $row['w_ft'] . "<BR>";
}
I read at http://php.net/manual/en/function.pg-execute.php that the second way returns “A query result resource on success or FALSE on failure.” So I tried to iterate through it with pg_fetch_assoc(). It works, but is that not deprecated along with the rest of the pg_sql functions? Should I be using something in the PDO to look at the results of the query?
For this reason, I’m inclined to use the first method while using PDO. Is this the norm?
My question is how to submit multiple values to either method. Neither method works when I try to submit an array to the prepared statement
$w_ft = array("48", "36");
$result = pg_execute($con, "my_query", array("48", "36"));
I thought that I was able to submit multiple values to the query in this way. How can I do this?
Thank you
Looks like you’re taking execute array wrong.
It takes values not for the consequent executions but for one execution only.
So, number of values should be equal to number of placeholders.
So it goes
for your
array("48", "36", "12")I am not a PG user though, so, I can confuse some syntax.