php連接MySQL數(shù)據(jù)庫(kù)的實(shí)際操作步驟與代碼
以下的文章主要介紹的是php連接MySQL數(shù)據(jù)庫(kù)的實(shí)際操作步驟以及對(duì)php連接MySQL數(shù)據(jù)庫(kù)的時(shí)機(jī)應(yīng)用代碼的描述,下面就是對(duì)其相關(guān)內(nèi)容的具體內(nèi)容描述,希望會(huì)給你帶來(lái)一些幫助在此方面。
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
PHP操作MySQL
extension=php_MySQL.dll打開
- <?php
- $servername = "127.0.0.1";
- $username = "root";
- $password = "123456";
- $conn = MySQL_connect($servername, $username, $password);
建立MySQL連接
- if($conn) {
echo "連接MySQL數(shù)據(jù)庫(kù)成功";
- }
- //MySQL_select_db("easytoo");
選擇要連接的數(shù)據(jù)庫(kù)
或者
- MySQL_query("use easytoo",$conn);
選擇要連接MySQL數(shù)據(jù)庫(kù)
- MySQL_query("SET NAMES utf8");
- $rs = MySQL_query("select id from et_category");
查詢獲取一個(gè)數(shù)據(jù)集
- MySQL_num_rows($rs);
得到記錄集總數(shù)
- while($row=mysql _fetch_array($rs))
循環(huán)數(shù)據(jù)集
- {
- echo "$row[0]<br>";
- }
- mysql_free_result($rs);
釋放rs
- mysql_close($conn);
關(guān)閉連接
- ?>
以上的相關(guān)內(nèi)容就是對(duì)php連接MySQL數(shù)據(jù)庫(kù)的介紹,望你能有所收獲。
【編輯推薦】