Php 如何使用MySQLi正确连接和查询MySQL?

Php 如何使用MySQLi正确连接和查询MySQL?,php,mysql,mysqli,Php,Mysql,Mysqli,我开始将我使用Mysql的站点转换为使用Mysql,但有一些问题。 有人可以帮助我如何使用Mysqli正确连接和查询Mysql吗 1) 以下是我的网站上的错误警告消息: a) 警告:mysql_query():第3556行/myside/xxxx/xxxxx/functions.php中的用户“localhost”(使用密码:No)的访问被拒绝 b) 警告:mysql_query():无法在第3556行的/myside/xxxx/xxxxx/functions.php中建立到服务器的链接 c)

我开始将我使用Mysql的站点转换为使用Mysql,但有一些问题。 有人可以帮助我如何使用Mysqli正确连接和查询Mysql吗

1) 以下是我的网站上的错误警告消息:

a) 警告:mysql_query():第3556行/myside/xxxx/xxxxx/functions.php中的用户“localhost”(使用密码:No)的访问被拒绝

b) 警告:mysql_query():无法在第3556行的/myside/xxxx/xxxxx/functions.php中建立到服务器的链接

c) 警告:mysql_results()希望参数1是resource,布尔值在第3558行的/myside/xxxx/xxxxx/functions.php中给出

2) 从第3544行到第3558行我使用的MYSQL查询函数代码:

// Get Custom Post Type post count
function get_stats($uid,$type,$sub_type = "all") {
if ($type == "reviews") {
    $result = mysql_query("SELECT COUNT(*) FROM wp_comments WHERE user_id =    $uid AND comment_approved = 1");
} elseif ($type == "listings") {
    if ($sub_type == "all") {
        $post_types =   get_post_types_custom(unserialize(EXCLUDED_CUSTOM_POST_TYPES));
    } else {
        $post_types = "'".$sub_type."'";
    }
    $result = mysql_query("SELECT COUNT(*) FROM wp_posts WHERE post_author = $uid AND post_type IN($post_types) AND post_status = 'publish'");
} else {
    $result = mysql_query("SELECT COUNT(*) FROM wp_posts WHERE post_author = $uid AND post_type = '$type' AND post_status = 'publish'");
}
return mysql_result($result,0);

非常感谢

鸣人-啊,是的,你说得对。它们是警告信息,不是错误,谢谢你指出——我会更新我的初始帖子。对于我来说,解决这些警告的最佳方式是什么,因为它们目前正公开显示在前端,让用户看到,这给人的印象是网站“坏了”


谢谢你的反馈,詹斯。想详细说明一下吗?我是个新手,我正在尝试“修复”我刚继承的代码,需要尽可能多的人手。“不要混合使用mysql和mysqli”。。。我是否在共享的代码中混用了它们?

我没有看到任何错误消息?!警告与错误不同。。。另外,我在您提供的代码中没有看到任何mysqli。请不要混合使用
mysql.*
和mysqli_*`