I’m trying to manually fetch a row on the WordPress table wp_post
from outside wordpress. I use PDO as follows:
$dbh2 = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD);
$dbh2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh2->prepare("SELECT WP.* FROM wp_posts WP, wp_term_relationships WTR WHERE WP.ID = WTR.object_id AND WP.ID = '821'");
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $result){
print_r($result);
}
The query works but I get a really weird result: the column post_content
is returned as NULL
even if it’s not empty (I checked on PhpMyAdmin. The post with ID: 821 exists and is full of content).
Why is it returning NULL on that column?
Additional notes:
post_content
column haslongtext
typepost_content
has a very long text inside, 2086 chars and full of html tags.
EDIT: The answer is correct and works. What’s weird is that var_dump
correctly outputs the content, while the function fb()
from FirePHP returns NULL. Be careful!
An implementation of the example to retrieve a ‘longtext’ (blob) column.
Note: the manual is incorrect about returning a stream as it returns a string containing the contents of the ‘lob’.
Table Definition
Sample Output: