Php changin mysql到mysqli

Php changin mysql到mysqli,php,mysqli,comments,Php,Mysqli,Comments,我一直都有这个错误,任何帮助。多谢各位 1-未定义变量:db_conx 及 2-mysqli_查询期望参数1为mysqli,给定null 我的代码: 。。。。。。。。。。。。。。。。。 ,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,您确实意识到您的查询在函数中,而您的数据库连接不是。 这就是你能做的。在函数中将变量$db_conx声明为全局变量 include_once("db_conx.php"); require_once ("users.php"); class Com

我一直都有这个错误,任何帮助。多谢各位

1-未定义变量:db_conx

2-mysqli_查询期望参数1为mysqli,给定null

我的代码:

。。。。。。。。。。。。。。。。。 ,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,

您确实意识到您的查询在函数中,而您的数据库连接不是。 这就是你能做的。在函数中将变量$db_conx声明为全局变量

include_once("db_conx.php");
require_once ("users.php"); 
class Comments{
public static function getComments( )       
{
    global $db_conx;

    $output = array();
    $sql = "SELECT * FROM comments order by comment_id desc";
    $query = mysqli_query( $db_conx, $sql );
    ...

您可以从中阅读有关全局范围的信息-$db_conx???$db_conx确实未定义。各位,在发布问题之前,您是否阅读了自己的代码,就好像您的db conn是一个全局范围,您没有将其包含在您的函数中。尝试添加全局$db_conx;看看这是否能解决问题。阅读关于全球范围的文章,永远不要使用它谢谢你,Kombian先生,你的建议很完美。
include_once("db_conx.php");
require_once ("users.php"); 
class Comments{
public static function getComments( )       
{
    global $db_conx;

    $output = array();
    $sql = "SELECT * FROM comments order by comment_id desc";
    $query = mysqli_query( $db_conx, $sql );
    ...