MySQL與php的串連操作要點,mysqlphp要點

來源:互聯網
上載者:User

MySQL與php的串連操作要點,mysqlphp要點

MySQL擴充庫操作MySQL資料庫的步驟如下:

1:擷取串連.

2:選取書庫。

3:設定作業編碼。

4:發送SQL指令(MySQL資料庫可以分為四種指令:

1:ddl: 資料定義語言 (Data Definition Language)。

2:dml:資料操語言(如CURD);

3:dql:資料查詢語言。(如select)

4:dtl:資料事物語言。

)。

5:接收返回結果,並且處理。

6:中斷連線。


具體的範例程式碼如下:

<pre name="code" class="php"><pre name="code" class="php"><pre name="code" class="php"><?php//1:串連資料庫$con=mysql_connect("localhost","root","toor");//如果沒有串連成功要報錯if(!$con){echo "串連失敗";exit();}//2: 選擇要操作的資料庫mysql_select_db("test");//3:發送SQL指令mysql_query("set names utf8");//設定查詢編碼$sql="select *from test1";$res=mysql_query($sql,$con);//4:返回結果(按行遍曆返回)while($row=mysql_fetch_row($res)){echo "$row[0]-------------$row[1]-----------$row[2]-----------$row[3]-----------$row[4]".'<br/>';}//5:釋放資源,關閉串連mysql_free_result($res);mysql_close($con);?>







要說明的是,這裡的所有的操作都是在記憶體的裡面去操作的,不能想當然的就是什麼東西,所以說,瞭解一些底層的東西還是有一定的好處的。




相關文章

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.