php串連mysql資料庫

來源:互聯網
上載者:User

標籤:php串連mysql資料庫

    

串連資料庫:使用物件導向的方法;1.造一個mysqli對象,造連線物件2.準備一條SQL語句3.執行SQL語句,如果是查詢語句。成功返回結果及對象4.從結果集對象裡找到資料;查詢屬性代碼:

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />

<?= MySQLi("localhost","root","12345678","heiheihei" = "select * from student" = ->query((    = ->   (?>

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />

最後的傳回值是一個集對象,為了方便清晰的看到結果 我們用到了fetch_all(),fetch_row(); fetch_object();

 

增刪改語句:增加一條資訊:

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />

//造連線物件$db = new MySQLi("localhost","root","12345678","heiheihei");//準備SQL語句$sql = "insert into cou values(‘3-111‘,‘嘿嘿‘,‘803‘)";    //執行SQL語句$r = $db ->query($sql);if($r)//如果$r是ture{    echo "執行成功";}else {    echo "執行失敗";}

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />

 

改變一條資訊:

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />

<?php//造連線物件$db = new MySQLi("localhost","root","12345678","heiheihei");//準備SQL語句$sql = "update cou set cname=‘哈哈‘ where tno=‘803‘";    //執行SQL語句$r = $db ->query($sql);if($r){    echo "執行成功";}else {    echo "執行失敗";}?>

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />

刪除:

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />

<?php//造連線物件$db = new MySQLi("localhost","root","12345678","heiheihei");//準備SQL語句$sql = "delete from cou where tno=‘803‘";    //執行SQL語句$r = $db ->query($sql);if($r){    echo "執行成功";}else {    echo "執行失敗";}?>

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="border:none;" />


php串連mysql資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.