Is it possible to create a table with the wpdb::prepare
function?
I read the documentation and tried to find examples but there where none that helped me.
Even creating a table with prepare doesn't give me any useful examples on Google.
Currently I'm creating my table like this:
public function createTableFromFields( $tablename, $fields ) {
//
$wpdb = $this->db;
$tablename = $wpdb->prefix . $tablename;
$sql = 'CREATE TABLE IF NOT EXISTS ' . $tablename . ' (id INT(6) UNSIGNED
AUTO_INCREMENT PRIMARY KEY';
foreach ( $fields as $field ) {
$sql .= ", $field TEXT";
}
$sql .= ')';
$result = $wpdb->query( $sql );
return $result;
}
But I learned that just using
$wpdb->query($sql)
is unsafe and that you should rather do it with
$wpdb->query(prepare($sql, $args).
So what do I put in $args
here and what would be the SQL code then using the query format strings?