wpdb select table no arguments -
i using new wpdb accessing database wordpress.
$mydb = new wpdb($username,$password,$database,$hostname); $sql = $mydb->prepare("select * " . $table); $results = $mydb->get_results($sql); this line produces error:
$sql = $mydb->prepare("select * " . $table); wpdb::prepare called incorrectly. wpdb::prepare() requires @ least 2 arguments.
all below statements produce same error:
$sql = $mydb->prepare("select * $table"); $sql = $mydb->prepare("select * '%s'", $table); how write without arguments?
(i using wordpress 3.5)
take single quotes off '%s' in last example , should work assuming $table valid table name.
edit: $wpdb->prepare() works similar php's sprintf() on more limited scale. if pass single parameter, doesn't do anything. see andrew nacin's post on after 3.5 released: http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/
the second parameter replace first instance of replaceable character set, i.e. %s, %d or %f, , third parameter replace second instance, , on.
Comments
Post a Comment