mysqli_query() 期望参数 1 为 mysqli,给定 null?令人困惑?
define('DB_HOST', 'localhost');
define('DB_USER', '******');
define('DB_PASSWORD', '************');
define('DB_NAME', '***********');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
class User {
function checkUser($uid, $oauth_provider,$username,$email,$twitter_otoken,$twitter_otoken_secret)
{
$query = mysqli_query($dbc,"SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
$result = mysqli_fetch_array($query);
if (!empty($result)) {
# User is already present
} else {
#user not present. Insert a new Record
$query = mysqli_query($dbc,"INSERT INTO si_table (oauth_provider, oauth_uid, user_name,email_id,twitter_oauth_token,twitter_oauth_token_secret) VALUES ('$oauth_provider', $uid, '$username','$email')") ;
$query = mysqli_query($dbc,"SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
$result = mysqli_fetch_array($query);
return $result;
}
return $result;
}
}
我收到这个错误!我不知道为什么?
mysqli_query() 期望参数 1 为 mysqli,第 14、15、20、21 和 22 行中给出的为 null!
define('DB_HOST', 'localhost');
define('DB_USER', '******');
define('DB_PASSWORD', '************');
define('DB_NAME', '***********');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
class User {
function checkUser($uid, $oauth_provider,$username,$email,$twitter_otoken,$twitter_otoken_secret)
{
$query = mysqli_query($dbc,"SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
$result = mysqli_fetch_array($query);
if (!empty($result)) {
# User is already present
} else {
#user not present. Insert a new Record
$query = mysqli_query($dbc,"INSERT INTO si_table (oauth_provider, oauth_uid, user_name,email_id,twitter_oauth_token,twitter_oauth_token_secret) VALUES ('$oauth_provider', $uid, '$username','$email')") ;
$query = mysqli_query($dbc,"SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
$result = mysqli_fetch_array($query);
return $result;
}
return $result;
}
}
I am getting this error! I don't know why?
mysqli_query() expects parameter 1 to be mysqli, null given in line 14,15,20,21 and 22!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
global $dbc;
添加到checkUser
的开头。该变量未在函数作用域中定义。Add
global $dbc;
to the beginning of thecheckUser
. The variable is not defined in the function scope.