gyclone
Forum Replies Created
-
Thank you for your response! I was unaware of WPDB at the time I posted this. I was trying to use a function I wrote for another program on a custom page and was getting a missing PDO driver error. I knew I had the PDO driver installed in my database because I use PDO all the time. It was late and I wasn’t thinking clearly and as a result, I wrongly assumed that my error was a result of WordPress not supporting PDO. I downloaded your plugin in hopes that it would solve my problem. It did not and I wrongly assumed I had failed to install the plugin properly. In fact, I had just made some silly errors in my code. Coincidentally, I stumbled upon WPDB the next morning and redid my function accordingly. Thanks!
Turns out I don’t even need the plugin to accomplish my goal. I thought it was required in order to use PDO from within WordPress, but apparently that is not the case.
In case anyone stumbles on this, my revised function (below) works without using any plugins.
`function twentytwelve_child_build_glossary(){
$dbhost = DB_HOST;
$dbname = DB_NAME;// Create PDO
$dbh->_pdo = new PDO(“mysql:host=$dbhost, dbname=$dbname”, DB_USER, DB_PASSWORD);
$dbh->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$strSQL = “SELECT term, definition FROM $dbname.wp_glossary ORDER BY term”;try {
// Prepare sql statement
$stmt = $dbh->_pdo->prepare($strSQL);
$stmt->execute();
$result = $stmt->fetchAll();
} catch (Exception $e) {
$result = “PDO Failed with Error: $e”;
}return $result;
}Sorry if I’ve wasted anyone’s time. Thanks!