postgres - pg_query works; pg_query_params doesn"t

postgres - pg_query works; pg_query_params doesn"t

am 15.06.2009 16:17:54 von Carol Walter

--Apple-Mail-11-480302271
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

Hello,

I have a php 5 and PostgreSQL 8.3.6. I wrote the original program
using pg_query. Now, I need to replace pg_query with
pg_query_params. I'm having trouble doing so. In this code pg_query
works but pg_query_params doesn't work. The code snippet is as follows:

if ($submit_info2 == "Submit")
{
include "connect_km_tezt.php"; // Connect to database
if ($get_name == Submit)
{
/************* Query using pg_query
*************************************/
/* $query2 = "SELECT \"fName\",\"mName\",\"lName\"
FROM \"tblPeople\"
WHERE \"peopleId\" = '$choose_name'";
$result2 = pg_query($query2) or die("Can't execute
query"); */
/************ Query using pg_query_params
***************************/
$query2 = pg_query_params('SELECT "fName","mName","lName"
FROM "tblPeople"
WHERE "peopleId" = $1', array($choose_name));
/* Process query result */
$rows2 = pg_num_rows($result2);
echo $rows2 . " rows returned.
";
while ($row2 = pg_fetch_array($result2))
{
$f_name_new = $row2['fName'];
$m_name_new = $row2['mName'];
$l_name_new = $row2['lName'];
echo "$fName $mName $lName
";
}

while (list($fName, $mName, $lName) =
pg_fetch_row($result2))
{
echo "$fName $mName $lName
";
}
}
if ($Info2 != "None")
{
echo "

You're entering a " . $Info2 . " for
  $f_name_new   $m_name_new   $l_name_new


";
}

The error message I get is as follows:

Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.

Please contact the server administrator, root@slis.indiana.edu and
inform them of the time the error occurred, and anything you might
have done that may have caused the error.

More information about this error may be available in the server error
log.

Question #1. Do you see why this isn't working.

Question #2. Is there some way I can see the query that is being
passed to the PostgreSQL server.

Question #3. Can I put an "or die" clause on pg_query_params.

I'm not sure how to debug this code.

Thanks,

Carol
--Apple-Mail-11-480302271--

Re: postgres - pg_query works; pg_query_params doesn"t

am 15.06.2009 17:05:53 von Jason Gerfen

Carol Walter wrote:
> Hello,
>
> I have a php 5 and PostgreSQL 8.3.6. I wrote the original program using
> pg_query. Now, I need to replace pg_query with pg_query_params. I'm
> having trouble doing so. In this code pg_query works but
> pg_query_params doesn't work. The code snippet is as follows:
>
> if ($submit_info2 == "Submit")
> {
> include "connect_km_tezt.php"; // Connect to database
> if ($get_name == Submit)
> {
> /************* Query using pg_query *************************************/
> /* $query2 = "SELECT \"fName\",\"mName\",\"lName\"
> FROM \"tblPeople\"
> WHERE \"peopleId\" = '$choose_name'";
> $result2 = pg_query($query2) or die("Can't execute query"); */
> /************ Query using pg_query_params ***************************/
> $query2 = pg_query_params('SELECT "fName","mName","lName"
> FROM "tblPeople"
> WHERE "peopleId" = $1', array($choose_name));
> /* Process query result */
> $rows2 = pg_num_rows($result2);
> echo $rows2 . " rows returned.
";
> while ($row2 = pg_fetch_array($result2))
> {
> $f_name_new = $row2['fName'];
> $m_name_new = $row2['mName'];
> $l_name_new = $row2['lName'];
> echo "$fName $mName $lName
";
> }
>
> while (list($fName, $mName, $lName) = pg_fetch_row($result2))
> {
> echo "$fName $mName $lName
";
> }
> }
> if ($Info2 != "None")
> {
> echo "

You're entering a " . $Info2 . " for
>   $f_name_new   $m_name_new   $l_name_new
>

";
> }
>
> The error message I get is as follows:
>
> Internal Server Error
>
> The server encountered an internal error or misconfiguration and was
> unable to complete your request.
>
> Please contact the server administrator, root@slis.indiana.edu and
> inform them of the time the error occurred, and anything you might have
> done that may have caused the error.
>
> More information about this error may be available in the server error log.
>
> Question #1. Do you see why this isn't working.
>
> Question #2. Is there some way I can see the query that is being passed
> to the PostgreSQL server.
>
> Question #3. Can I put an "or die" clause on pg_query_params.
>
> I'm not sure how to debug this code.
>
> Thanks,
>
> Carol

pg_error() will tell you why. more then likely you should test the valid
resource coming from the pg_connect function.


--
Jas
"Tomorrow isn't promised so we live for today"

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php