当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Wordpress $wpdb mysqli_prepare statements

问题描述:

I am trying to convert a website to use the $wpdb functionality and can't for the life of me figure out how to actually create a prepared statement that I can bind to and execute. The WP prepare statement only sanitizes the values it actually does nothing near a actual prepare. This seems extremely unproductive and just dumb am I missing something? Does anyone know if there is a way to get a hold of the underlying mysqli functionality from the $wpdb?

I have tried without much success:

$stmt = $wpdb->mysqli_prepare($wpdb, $sql);

Hoping to use the "Magic Methods" to get ahold of the mysqli stuff. Anyone have any ideas?

What I am after is MySql Prepare and MySql Bind Param most importantly. For example something like:

/* create a prepared statement */

if ($stmt = $wpdb->prepare("SELECT District FROM City WHERE Name=?")) {

/*** Most Important what I am after ***/

$stmt->bind_param("s", $city);

/* execute query */

$stmt->execute();

/* bind result variables */

$stmt->bind_result($district);

/* fetch value */

$stmt->fetch();

printf("%s is in district %s\n", $city, $district);

/* close statement */

$stmt->close();

}

What I am not able to do is figure out a way to be able to bind variables since WP does not actually create a mysqli prepared statement. Using prepared statments like this enables me to be able to put all the changes/updates/deletes into basically one Read/Write to the MySql server not executing one query for every change. If I can get ahold of the native smtp object from the $wpdb I could do what I need.

分享给朋友:
您可能感兴趣的文章:
随机阅读: