Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我听说总是使用事先准备好的语句,但是wordpress呢?_Php_Mysql_Wordpress - Fatal编程技术网

Php 我听说总是使用事先准备好的语句,但是wordpress呢?

Php 我听说总是使用事先准备好的语句,但是wordpress呢?,php,mysql,wordpress,Php,Mysql,Wordpress,问题1。我知道我不需要为wbdb->insert或wbpdb->delete执行这些操作,但是人们说无论如何都要执行这些操作,即使类会为您执行这些操作 // I've got a select count query function and should use it here. global $wpdb; $entries = $wpdb->prefix . 'simpledir_entries'; $count = $wpdb->get_var("SELECT COUNT(*

问题1。我知道我不需要为wbdb->insert或wbpdb->delete执行这些操作,但是人们说无论如何都要执行这些操作,即使类会为您执行这些操作

// I've got a select count query function and should use it here.

global $wpdb;
$entries = $wpdb->prefix . 'simpledir_entries';
$count = $wpdb->get_var("SELECT COUNT(*) FROM $entries WHERE rel = $id;");

if($count <= 0){
    return false;
}else{
    return true;
}   
问题2。我不知道如何将其表述为完全安全的适当准备声明。$entries和$id都需要它吗


感谢您回答第一个问题:WordPress中的Prepare语句为安全执行准备SQL查询。它使用类似sprintf的语法

对于第二个问题:在get_var查询中,语句应该是这样的:

global $wpdb;
$entries = $wpdb->prefix . 'simpledir_entries';
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM %s WHERE rel = %d;", $entries, $id));

if($count <= 0){
    return false;
}else{
    return true;
}
祝你好运

您可以验证$id是否为数字-如果是数字$id。。。然后继续-否则die$条目应被列入白名单,然后传入$应该绑定id。看见