由于新的PHP版本,过时的功能

时间:2017-05-24 10:00:27

标签: php blogs

所以我最近将我的PHP更新为7,现在我的博客停止了工作,我知道它与过时的代码有关,但是我无法找到更新它的方法,任何建议?

这是我的代码

<?php

function add_post(){
$title      = mysql_real_escape_string($title);
$contents   = mysql_real_escape_string($contents);

mysql_query("INSERT INTO `posts` SET
            `title`      = '{$title}',
            `contents`   = '{$contents}',
            `date_posted`= NOW()");
}
function edit_post($id,$title,$contents)
{
$id = (int)$id;
$title = mysql_real_escape_string($title);
$contents = mysql_real_escape_string($contents);
}

function delete($table, $id){
$table = mysql_real_escape_string($table);
$id    = (int)$id;
mysql_query("DELETE FROM `{$table}` WHERE `id`= {$id} ");

}
function get_posts($id = null, $cat_id = null){
$posts = array();
$query = "SELECT
          `posts`.`id` AS `post_id` ,
           `title`,`contents`,`date_posted`.`name`
           FROM `posts`
           INNER JOIN `categories` ON `categories`.`id` = `posts`.`cat_id` " ;
if(isset($id)){
    $id = (int)$id;
    $query .= " WHERE `posts`.`id` = {$id} ";
         }
if(isset($cat_id)){
    $cat_id = (int)$cat_id;
    $query .= " WHERE `cat_id` = {$cat_id} ";
         }         

$query .= "ORDER BY `post_id` DESC";




   return $posts;
}

感谢您的时间。

1 个答案:

答案 0 :(得分:-2)

在php 7中删除了Mysql_real_escape_string和mysql_query

您可以使用Mysqli作为替代品。

http://php.net/manual/en/mysqli.real-escape-string.php