Home  >  Article  >  Backend Development  >  PHP新手跪求各位解决 Couldn't fetch mysqli 这个有关问题

PHP新手跪求各位解决 Couldn't fetch mysqli 这个有关问题

WBOY
WBOYOriginal
2016-06-13 12:21:386505browse

PHP新手跪求各位解决 Couldn't fetch mysqli 这个问题!
弄了个工具类让其他类去调用,注释了的地方是一开始写的,可是报这样的错误
于是我就只好直接 把¥link的内容写进去:$rs=mysqli_query(mysqli_connect("localhost", "root", "yjy9382","liuyanban") ,$sql) 
这样竟然不报错!各位大神救救小弟吧,我已经试了很多办法都不知道怎么错,因为以前学JAVA,这两天才自己的PHP,可能犯低级错误自己看不出来,还望大家指点一下谢谢!


class SqlHelper{
   
    /*
    public $link;
    public $dbname="liuyanban";
    public $username="root";
    public $password="yjy9382";
    public $host="localhost";
  
   
    //连接数据库
    public function __construct(){
    $this->link=mysqli_connect($this->host, $this->username, $this->password,$this->dbname);

  if(!$this->link){
      die(mysqli_errno());
 }
    }

     */

    
    //执行Dql语句
    public function execute_Dql($sql){
       // $rs=mysqli_query($this->link ,$sql) ;
        $rs=mysqli_query(mysqli_connect("localhost", "root", "yjy9382","liuyanban") ,$sql) ;
        return $rs;
    } 
------解决思路----------------------
把连接数据库的单独执行,
------解决思路----------------------
我记得mysqli是面向对象的吧,
链接数据库:$this->link=new mysqli($host,$user,$password,$db);
操作sql:$this->link->query($sql)
------解决思路----------------------
mysqli 提供 Object oriented style  和 Procedural style 方式。
面向对象


$db_host="localhost";?????//连接的服务器地址?
$db_user="root";??????????????//连接数据库的用户名?
$db_psw="root";???????????????//连接数据库的密码?
$db_name="sunyang";???//连接的数据库名称?
$mysqli=new?mysqli();?
$mysqli->connect($db_host,$db_user,$db_psw,$db_name);??>


面向过程

$connection = mysqli_connect("localhost","root","root","sunyang");
if ( $connection ) {
echo "数据库连接成功";
}else {
echo "数据库连接失败";
} ?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn