Home  |  Linux  | Mysql  | PHP  | XML
From:Jason Gerfen Date:Mon Jun 15 15:05:53 2009
Subject:Re: postgres - pg_query works; pg_query_params doesn't
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. <br />";
> 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 <br />";
> }
>
> while (list($fName, $mName, $lName) = pg_fetch_row($result2))
> {
> echo "$fName $mName $lName <br />";
> }
> }
> if ($Info2 != "None")
> {
> echo "<h2>You're entering a " . $Info2 . " for
> &nbsp; $f_name_new &nbsp; $m_name_new &nbsp; $l_name_new
> </h2> ";
> }
>
> 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"
Navigate in group php.db at sever news.php.net
Previous Next


Your recent visits
Re: [PHP-DB] pdo_pgsql connection problem
pdo_pgsql connection problem
Re: [PHP-DB] 64-bit Linux -- Fatal ... undefined function mysql_connect()
Test results for 5.2.5 [failed]



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants