|
Posted by Schraalhans Keukenmeester on 04/29/07 16:00
On Sun, 29 Apr 2007 08:13:40 -0700, mpar612 wrote:
> I am working on converting some old PHP 4 scripts to PHP 5. I used to
> use the PEAR DB module in PHP 4 and in PHP 5 I want to use PDO.
>
> I am using this code to connect to the DB:
>
> $dbh = new PDO('mysql:host=localhost;dbname=name', 'username',
> 'password');
>
> Later on in the same page I use this code and it works just fine:
>
> foreach($dbh->query('SELECT artist_id, artist_name FROM 10spot_artist
> ORDER BY artist_name') as $row) {
[SNAP]
> }
> $dbh = null;
>
> Later on in the same page I use the following code and it doesn't
> work. I don't get any errors or anything the page just stops executing
> right at this code. I'm new to using PDO. Any thoughts on why this
> doesn't work? Thanks in advance!
>
> $head_sel_sql = $dbh->query('SELECT select_id, headline_id FROM
> 10spot_head_sel');
(assuming you posted all relevant code)
You create a PDO instance $dbh, use it, and then you destroy the object:
the next query can never be executed. Why the $dbh=null; ?
Either strip those out of your code, or re-instantiate a PDO object before
using it again.
The object will automatically be destroyed by PHP when the script ends.
HTH
Sh
[Back to original message]
|