php串連mysql步驟

來源:互聯網
上載者:User

標籤:

 

 1 1.      編寫php程式完成對使用者表的顯示 2 代碼 3 <?php 4        //mysql擴充庫操作mysql資料庫步驟如下 5        //1. 擷取串連 6        7        $conn=mysql_connect("127.0.0.1","root","root"); 8        if(!$conn){ 9               die("串連失敗".mysql_error());10        }11       12        //2. 選擇資料庫13        mysql_select_db("test");14        //3. 設定作業編碼(建議有)!!!15        mysql_query(“set names utf8”); //保證我們的php程式是按照utf8碼操作.16        //4. 發送指令sql (ddl 資料定義語句 , dml(資料操作語言 update insert ,delete) ,dql (select ), dtl 資料事務語句 rollback commit... )17        $sql="select * from user1";18        //函數19        //$res 表示結果集,你可以簡單的理解就是 一張表.20        $res=mysql_query($sql,$conn);21        //var_dump($res); //mysql result 資源類型22       23        //5. 接收返回的結果,並處理.(顯示)24        // mysql_fecth_row 會依次取出$res結果集的下一行資料,賦值給$row25        // $row就是一個數組, 樣式array(5) { [0]=> string(1) "1" [1]=> string(2) "zs" [2]=> string(32) "e10adc3949ba59abbe56e057f20f883e" [3]=> string(11) "[email protected]" [4]=> string(2) "30" }26               //mysql_fetch_assoc mysql_fetch_array27               while($row=mysql_fetch_row($res)){28               //第一種取法是 同 $row[$i]29               //echo "<br/> $row[0]--$row[1]--$row[2]";30               //echo "<br/>";31               //var_dump($row);32               //第二種取法33               foreach($row as $key => $val){34                      echo "--$val";35               }36               echo "<br/>";
          mysql_free_result($res);    //釋放記憶體
          //mysql_close($conn);可寫可不寫
37 }

 

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.