PHP新手跪求各位解決 Couldn't fetch mysqli 這個有關問題

來源:互聯網
上載者:User
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 "資料庫連接失敗";
} ?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.