I have updated an old version of Wordpress (3.0.1) to 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?
mysql_* has been deprecated and now its not available in newer versions of 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).
Or use mysqli_*
extension for WordPress 4.4.
Or in the last change queries as per wordpress $wpdb->get_row
.
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.
Also they offer prepared statements which should be used to prevent SQL injection attacks. 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:
$wpdb->query( $wpdb->prepare(
"SELECT code FROM wp_kk_video WHERE id = '%d'",
$video_id
) );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.