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;dbna me=name', 'username',
'password');
Later on in the same page I use this code and it works just fine:
foreach($dbh->query('SELEC T artist_id, artist_name FROM 10spot_artist
ORDER BY artist_name') as $row) {
$id = $row['artist_id'];
$name = stripslashes($r ow['artist_name']);
echo "<tr>
<td width=\"240\" height=\"35\"
background=\"im ages/ArtistColumnBac k.gif\">
<b><font face=\"Arial\" size=\"2\"
color=\"#FFFFFF
\"> &nb sp;
<a href=\"Artist.p hp?id=$id\" style=
\"text-decoration: none\">$name</a></font></b></td>
</tr>";
}
$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('SELEC T select_id, headline_id FROM
10spot_head_sel ');
$headline_id = $head_sel_sql['headline_id'];
$dbh = null;
$head_display = $dbh->query('SELEC T headline_id,
date, headline, headline_descri ption FROM 10spot_headline s WHERE
headline_id = $headline_id');
$display_head =
stripslashes($h ead_display['headline']);
$display_date = $head_display['date'];
$display_descri ption =
stripslashes($h ead_display['headline_descr iption']);
echo "<tr>
<td><i><b><fo nt face=\"Arial\" color=\"#BE2E2E
\">$display_hea d</font></b></i></td>
<td>
<p align=\"right\" ><font size=\"2\" face=
\"Arial\">$disp lay_date</font></td>
</tr>
<tr>
<td colspan=\"2\">
<font face=\"Arial\" style=\"font-size: 9pt\">
$display_descri ption</font></td>
</tr>";
$dbh = null;
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;dbna me=name', 'username',
'password');
Later on in the same page I use this code and it works just fine:
foreach($dbh->query('SELEC T artist_id, artist_name FROM 10spot_artist
ORDER BY artist_name') as $row) {
$id = $row['artist_id'];
$name = stripslashes($r ow['artist_name']);
echo "<tr>
<td width=\"240\" height=\"35\"
background=\"im ages/ArtistColumnBac k.gif\">
<b><font face=\"Arial\" size=\"2\"
color=\"#FFFFFF
\"> &nb sp;
<a href=\"Artist.p hp?id=$id\" style=
\"text-decoration: none\">$name</a></font></b></td>
</tr>";
}
$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('SELEC T select_id, headline_id FROM
10spot_head_sel ');
$headline_id = $head_sel_sql['headline_id'];
$dbh = null;
$head_display = $dbh->query('SELEC T headline_id,
date, headline, headline_descri ption FROM 10spot_headline s WHERE
headline_id = $headline_id');
$display_head =
stripslashes($h ead_display['headline']);
$display_date = $head_display['date'];
$display_descri ption =
stripslashes($h ead_display['headline_descr iption']);
echo "<tr>
<td><i><b><fo nt face=\"Arial\" color=\"#BE2E2E
\">$display_hea d</font></b></i></td>
<td>
<p align=\"right\" ><font size=\"2\" face=
\"Arial\">$disp lay_date</font></td>
</tr>
<tr>
<td colspan=\"2\">
<font face=\"Arial\" style=\"font-size: 9pt\">
$display_descri ption</font></td>
</tr>";
$dbh = null;
Comment