Reply to Re: PHP 5 and PDO

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация