Search Postgresql Archives

Re: php + postgresql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mick,

1.
I ended up using pg_prepare() and pg_execute() as pg_query() alone just didn't seem to work. But SELECT statements seemed to be cached or persistent in some way, such that they "lived" beyond the life of the PHP script. Is there something I need to know about persistent behaviour in PG that doesn't exist in MySQL?

Do you have an example? and what makes you say they are persisting?

2.
Another problem was that no matter how many times I checked and re- checked code, or which pg_fetch_* function I used, copying an array member and trying to use it later just would not work, eg

while ($row = pg_fetch_array($query)) {
 $content = $row[0]
}

echo $content;

$content was always 'undeclared'.

are you sure pg_fetch_array($query) is returning any rows? (try echo $row[0]; within the while loop)

3.
Some examples I found used PHP's pg_num_rows() function to count the rows in a result, then iterated through them with a "for" loop ... is this required behaviour (PHP docs don't appear to discuss this)?

I often do something along the lines of this:

if($stat = pg_exec($dbh, $sql))
    {
     if($rows = pg_numrows($stat))
         {
           for($i=0; $i < $rows; $i++)
                 {
                  $data = pg_fetch_array($stat, $i);

                  # do something with $data
                 }
         }
     else{echo "no rows returned";}
   }
 else{echo "query failed";}

4.
Another weird one was that this statement always failed:

$name = "file.php";
SELECT fld_content FROM tbl_page WHERE fld_name='$name'

is $name being interpolated correctly when you use it.... maybe use:

$sql = "SELECT fld_content FROM tbl_page WHERE fld_name='".$name."'";

(or use a prepared statement)

while this one always worked:

SELECT fld_content FROM tbl_page WHERE fld_pid=1

in a three column table:

fld_pid serial PRIMARY KEY,
fld_name varchar(100) NOT NULL,
fld_content text NOT NULL

while everything worked fine from the psql console.


... but this post is getting too unwieldy. I am reading documentation but am also under some pressure to get basic things up and running. Any pointers to good documentation covering PHP + PG, or any well known gotchas?

PS If people want to throw MySQL->PostgreSQL gotchas at me I'm happy to collate and write up.

Thanks again
Mick

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux