I have set up a basic "guestbook" script. It uses a table named guestbook and currently has two rows in it. Using the mysql_* commands I can successfully access the table and display the information as desired. However, I'm trying to look into PDO and currently am attempting to convert the code to PDO. I'm having a bizarre error, though.
The code always echo's "Whoops" as apparently, the query() command fails to retrieve any data. When I do var_dump($data), the output is bool(false). I've tried searching the Internet but found no satisfactory solutions. I know for a fact that there are two rows of data in the table guestbook, yet query() is failing to retrieve them. Can anyone help me understand what's wrong? Does Boru not have part or all of PDO enabled?
(And before anyone says anything, I realize there are such thing as prepared statements. I'm just starting with PDO, cut me some slack. )
PHP:
// Connect to the database.
$con=new PDO("mysql:localhost;dbname=db","username","password");
// Grab the data.
$select="SELECT * FROM guestbook";
$data=$con->query($select);
if(!$data){
echo "Whoops";
}else{
echo "Good so far";
}
$con=null;
The code always echo's "Whoops" as apparently, the query() command fails to retrieve any data. When I do var_dump($data), the output is bool(false). I've tried searching the Internet but found no satisfactory solutions. I know for a fact that there are two rows of data in the table guestbook, yet query() is failing to retrieve them. Can anyone help me understand what's wrong? Does Boru not have part or all of PDO enabled?
(And before anyone says anything, I realize there are such thing as prepared statements. I'm just starting with PDO, cut me some slack. )
Last edited: