简体   繁体   English

Wordpress不执行mysql_query()

[英]Wordpress not executing mysql_query()

I have updated an old version of Wordpress (3.0.1) to 4.4.2. 我已经将旧版本的Wordpress(3.0.1)更新为4.4.2。 Everything works, except for one plugin, which has all queries in this style. 一切正常,除了一个插件,该插件具有这种样式的所有查询。 I have used a custom page to test a simple query and can verify that the query returns nothing: 我已经使用一个自定义页面来测试一个简单的查询,并且可以验证该查询没有返回任何内容:

$query = "SELECT code FROM wp_kk_video WHERE id = '0'";
$result = mysql_query ($query);

Then I replaced that query with the following: 然后,我将查询替换为以下内容:

$query = $wpdb->get_row( "SELECT code FROM wp_kk_video WHERE id = '0'" );
$result = $query->code;

And it worked perfectly. 而且效果很好。

So why has Wordpress stopped executing the old type of mysql_query queries? 那么,为什么Wordpress停止执行旧类型的mysql_query查询?

mysql_* has been deprecated and now its not available in newer versions of Php. mysql_ *已被弃用,现在在新版本的Php中不可用。

Suggestions: 意见建议:

Use PHP 5.3+ or 5.4+ (PHP 5.5+ PHP 5.6+ PHP 7.0+ PHP 7.1+ is not supported for now). 使用PHP 5.3+或5.4+(目前不支持PHP 5.5+ PHP 5.6+ PHP 7.0+ PHP 7.1+)。

Or use mysqli_* extension for WordPress 4.4. 或对WordPress 4.4使用mysqli_*扩展名。

Or in the last change queries as per wordpress $wpdb->get_row . 或者在最后一次更改查询中,按wordpress $wpdb->get_row

PHP Unsupported Branches PHP不支持的分支

WordPress Forum WordPress论坛

Wpdb Class References: Wpdb类参考:

Plugins should always use the wpdb class/variable abstraction, so that updates like yours don't break your blog as Wordpress code already looks which mysql* functions are available. 插件应始终使用wpdb类/变量抽象,以使像您这样的更新不会破坏您的博客,因为Wordpress代码已经看起来可以使用哪些mysql *功能了。

Also they offer prepared statements which should be used to prevent SQL injection attacks. 他们还提供了准备好的语句,这些语句应用于防止SQL注入攻击。 If the id parameter in your example is a user provided value and therefore possible evil input, you should rewrite it to the following to be on the secure side: 如果示例中的id参数是用户提供的值,因此可能是邪恶的输入,则应将其重写为以下内容,以确保安全:

$wpdb->query( $wpdb->prepare( 
    "SELECT code FROM wp_kk_video WHERE id = '%d'", 
    $video_id
) );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM