The "english" version is dosplaying japanese or chinese letters, and I don't understand anything :D
Most of these functions returns NULL when no results are matched by the query. I think these should be commented in functions like get_var, etc.
I think there are errors in this article but since they are the whole way through I thought I would check first before editing it.
In the examples, such as:
$name = $wpdb->get_var("SELECT cat_name FROM $wpdb->linkcategories WHERE cat_id=4");
I can only get this to work if I come out of the string before putting the $wpdb->table_name in, like this:
$name = $wpdb->get_var("SELECT cat_name FROM ".$wpdb->linkcategories." WHERE cat_id=4");
This makes logical sense to me too, but since it is the same in every example here, i thought I would query it first.
Came here to discuss the same issue. In my experience, removing $wpdb-> from within the query string also returns the correct result. For example,
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10");
does not work, however;
$mylink = $wpdb->get_row("SELECT * FROM links WHERE link_id = 10");
does work.
Thanks, John-Michael 05:49, 25 March 2010 (UTC)
This is perfectly valid and should work:
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10");
Make sure that you are using double quotes, and not single quotes. If you want to be clearer, you can always do this:
$mylink = $wpdb->get_row("SELECT * FROM {$wpdb->links} WHERE link_id = 10");
But it isn't necessary. J.D. Grimes 19:11, 7 June 2013 (UTC)
Why this article suggests to escape every query when WordPress just do automatically escaping for all $_POST in wp-settings.php with:
// Escape with wpdb. $_GET = add_magic_quotes($_GET ); $_POST = add_magic_quotes($_POST ); $_COOKIE = add_magic_quotes($_COOKIE); $_SERVER = add_magic_quotes($_SERVER);
also if you escape again results in escaping also the escape and every time # of "\" grows in an exponential way.
How WP access data from another database ?
I had open thread here >> http://wordpress.org/support/topic/249491
One can't use get_col to output *anything* (same with get_results targeting column name), as the column info is now set to protected. And so, the claim that one can run "any" query on the db using $wpdb is now at best misleading.
var_dump($wpdb) returns, "...["result":protected]=> resource(38) of type (mysql result) ["col_info":protected]=> NULL..."
See: http://core.trac.wordpress.org/ticket/20838
The text currently says " If a MySQL error is encountered, the function will return FALSE. Note that since both 0 and FALSE may be returned, you can use the equality == operator to test for falsy returns (i.e., a returned value that is logically FALSE). Using the identicality === operator may result in unexpected behavior as it compares the types returned in addition to the values...". That seems odd, isn't it the == operator that would confuse an error with a 0 result-set? Seems to me it is the == operator that would result in unexpected behavior, not the === operator, which would not confuse false with 0. Maratbn (talk) 05:54, 30 March 2015 (UTC)maratbn