新php版本导致函数过时
所以我最近更新了我的PHP到7,现在我的博客停止工作了,我知道这与过时的代码有关,但我真的想不出更新的方法,有什么建议吗 这是我的密码新php版本导致函数过时,php,blogs,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 `t
<?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;
}
php 7中删除了Mysql\u real\u escape\u字符串和Mysql\u查询 您可以使用Mysqli作为替代
mysql扩展已从7.0.0中删除。您应该切换到mysqli(注意额外的i)或PDO。最好使用
mysqli
或PDO
,因为mysql
已被弃用。这里有更多信息:@Vikrant不要把新手送到学校。那个网站是有害的。我们需要为学校使用pdo,他们建议学校,我会看看使用mysqli或pdo。。。对于mysqli,将mysql.*
替换为mysqli.*
,函数的第一个参数必须是连接对象。例如:mysqli\u查询($con,“你的查询”)
。。。注意这是一个快速的方法。。。更好的方法是使用PDO和准备好的语句不,替换是“准备好的语句”,我没有说是替换,我说是替换,如果由我决定,我会说每个人都使用雄辩的语句,那会更糟