How To Handle MySQL-Errors With WPDB-Class?
-
Hi,
I wonder how I can find out if my MySQL query led to an error.
I am using a function like this:
function block_ip($ip) { $query = "INSERT IGNORE INTO wp_blocked_ips (ip) VALUES ('$ip')"; $wpdb =& $GLOBALS['wpdb']; return $wpdb->get_results($query); }
Then, I tried to call it like this:
$blocked = block_ip('123.456.789.012'); if ($blocked) { echo "Everything went fine."; } else { echo "An error has occured!"; }
But somehow, this is not working, as $blocked always seems to be true, even if there was an error with the query.
How can I handle an error resulting from a MySQL query?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How To Handle MySQL-Errors With WPDB-Class?’ is closed to new replies.