<?php # Nettuts Tutorial using PHP Data Objects (PDO),
/**This file contains the database access information
*This file also establishes a connection to mySQL
*and selects the database.
*Set the database access information as constants:
**/
// print_r(PDO::getAvailableDrivers());
DEFINE('DB_USER', 'root');
DEFINE('DB_PASSWORD', 'root');
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_NAME', 'sitename');
$php = "htmlspecialchars";
try {
#MySQL with PDO_MYSQL
// $DBH = new PDO("mysql:host={$php(DB_HOST)}; dbname={$php(DB_NAME)}", root, root};
$DBH = new PDO("mysql:host=localhost; dbname= sitename", root, root);
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# UH-OH! Typed DELECT instead of SELECT!
$DBH->prepare('DELECT name FROM people');
} catch (PDOException $e) {
echo "I'm sorry, Dave. I'm afraid I can't do that.";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
?>
The Console in OS X returns "[14-Aug-2011 15:59:59] PHP Notice: Use of undefined constant root - assumed 'root' in /Applications/MAMP/htdocs3/nettuts/PHP/PDO for Database Access/mysql_pdo_connect.php on line 20."
I've "googled" and found a partial answer here. So I was hoping for completion here.
TIA