We’re having an issue adding MySQL queries to our page. It seems that whenever something is run at the top of the page, the rest of the markup and php functions to follow don’t show up/aren’t run.
Here’s a sample query that causes this issue:
global $wpdb;
$add_query = "CREATE TABLE thetesttable
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
product VARCHAR(50)
)";
$wpdb->query($add_query) or die(mysql_error());
Loading the page once results in a blank page.
The second time, we see Table 'thetesttable' already exists, which means that our queries are getting through.
There are no other errors on the page or anything else detected by Google Chrome.
What could be causing this problem?
Many thanks,
Justian Meyer
The problem is that your query is returning 0 which is interpreted as false in your statment:
From the
wpdbclass reference:What you should do is something like:
Edit: By the way, also note that you should not use
mysql_error()like you do when you use the wpdb class. To get the last error, you can use$wpdb->print_error();.