PHP MySqli中未选择任何数据库

PHP MySqli中未选择任何数据库,php,mysql,mysqli,Php,Mysql,Mysqli,我已经切换到MySQLi,在加载登录页面时遇到了一些问题。我得到错误“没有选择数据库” 这是我的连接码 <?php // config $config['host'] = ""; $config['user'] = ""; $config['pass'] = ""; $config['db'] = ""; // the @ sign is an error supressor, meaning we can use our own error messages, this con

我已经切换到MySQLi,在加载登录页面时遇到了一些问题。我得到错误“没有选择数据库”

这是我的连接码

<?php
// config

$config['host'] = "";

$config['user'] = "";

$config['pass'] = "";

$config['db'] = "";

// the @ sign is an error supressor, meaning we can use our own error messages, this connects and selects db
@($GLOBALS["___mysqli_ston"] = mysqli_connect(
    "$config[host]", "$config[user]", "$config[pass]"
)) 
or die("error :".((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))."");
@((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $config['db'])) 
or die("error:".((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))."");

?>

检查下面的代码

// config
$config['host'] = "localhost"; // host name of your mysql server

$config['user'] = "root"; // your mysql username

$config['pass'] = ""; // your mysql password

$config['db'] = "sb_posts"; // the database your table is in.

// the @ sign is an error supressor, meaning we can use our own error messages, this connects and selects db
@($GLOBALS["___mysqli_ston"] = msqli_connect("".$config['host']."","".$config['user']."","".$config['pass']."","".$config['db'] ."")) or die("There was an error connecting to the database, MySql said:<br />".((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))."");
@((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $config['db'])) or die("There was an error connecting to the database, MySql said:<br />".((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))."");
//配置
$config['host']=“localhost”;//mysql服务器的主机名
$config['user']=“根”;//您的mysql用户名
$config['pass']=“”;//您的mysql密码
$config['db']=“sb_posts”;//表所在的数据库。
//@符号是一个错误抑制器,这意味着我们可以使用自己的错误消息,这将连接并选择db
@($GLOBALS[“\uuuuuu mysqli\u ston”]=msqli\u connect(“$config['host']”、“$config['user']”、“$config['pass']”、“$config['db']”)或死(“连接到数据库时出错,MySql说:
((是对象($GLOBALS[“\uuuuuuuuuuuuuu MySql\u ston”)))))?mysqli\u错误($GLOBALS[“\uuuuuuuqlu mysqli=”):($mysqlu-error)()?$\uuuuu mysqli\u res:false)); @((bool)mysqli_query($GLOBALS[“\uuuuuuu mysqli_ston”],“USE”$config['db'])或die(“连接到数据库时出错,MySql说:
”)((is_object($GLOBALS[“\uuuuuuuuuuuu mysqli_ston”))?mysqli_错误($GLOBALS[“\uuuuuuuuuuuuuuuuuuu mysqli_u-ston”]):($):($uuuuuuuuuuuuuuuuuuuuuuuuuu-mysqli-mysqli-res=mysqli-res=mysqli-connect-error())):mysqli-false;
警告:使用
@
运算符调用方法时,不要抑制错误。如果出现问题,您希望了解它,并需要采取纠正措施,为用户显示有用的消息,记录问题,或所有这些等等。如果忽略试图指出严重问题的错误,这也会使调试问题变得更加复杂。如果需要,可以在连接中传递数据库名称。也许这就是诀窍?这段代码太难理解了,你真的应该试着简化它。我不知道你在那里用
@
做什么,但它看起来非常非常危险。不知道你在做什么,除了让你的代码几乎完全无法阅读和维护之外
   public function __construct($host = 'localhost', $u = 'root', $p = '', $db = 'db')
    {
    $this->host = $host;
    $this->user = $u;
    $this->pwd = $p;
    $this->db = $db;

    //connect to the database
    $this->conxn = mysqli_connect($this->host, $this->user  , $this->pwd, $this->db)
                    or trigger_error($this->error = mysqli_error($this->conxn));


}