共計(jì) 937 個(gè)字符,預(yù)計(jì)需要花費(fèi) 3 分鐘才能閱讀完成。
自動(dòng)寫代碼機(jī)器人,免費(fèi)開通
這篇文章主要介紹了 navicat 數(shù)據(jù)庫(kù)連接 php 的方法,具有一定借鑒價(jià)值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓丸趣 TV 小編帶著大家一起了解一下。
第一步,打開 Navicat,新建數(shù)據(jù)庫(kù)。
第二步,在數(shù)據(jù)庫(kù)中新建表。
第三步,保存表。
第四步,表中添加數(shù)據(jù)。
第五步,打開 ide,輸入以下 php 代碼,使用 localhost 打開該 php 文件。
?php
// ip 地址、用戶名、密碼
$con=mysql_connect( localhost , root , 123456
// 判斷是否連接成功
if(!$con){ die( 數(shù)據(jù)庫(kù)連接失敗 .mysql_error());
}else{
// 設(shè)置編碼格式
mysql_query( set name utf8
// 選擇數(shù)據(jù)庫(kù)
mysql_select_db(test ,$con);
// 選擇數(shù)據(jù)表
$result=mysql_query( select * from user
// 輸出表格及 th
echo table border= 2 width= 300
tr
th id /th th name /th
th password /th
/tr
// 遍歷數(shù)據(jù)表中的內(nèi)容
while($row=mysql_fetch_array($result)){
echo tr
// userid === 用戶 id 與數(shù)據(jù)表中的 id 名稱對(duì)應(yīng)
echo td .$row[userid]. /td
// username === 用戶名稱 與數(shù)據(jù)表中的 username 名稱對(duì)應(yīng)
echo td .$row[username]. /td
// password === 用戶密碼 與數(shù)據(jù)表中的密碼對(duì)應(yīng)
echo td .$row[password]. /td
echo /tr
}
echo /table
}
// 關(guān)閉數(shù)據(jù)庫(kù)
mysql_close($con);
?
瀏覽器中顯示的頁(yè)面:
感謝你能夠認(rèn)真閱讀完這篇文章,希望丸趣 TV 小編分享 navicat 數(shù)據(jù)庫(kù)連接 php 的方法內(nèi)容對(duì)大家有幫助,同時(shí)也希望大家多多支持丸趣 TV,關(guān)注丸趣 TV 行業(yè)資訊頻道,遇到問題就找丸趣 TV,詳細(xì)的解決方法等著你來學(xué)習(xí)!
向 AI 問一下細(xì)節(jié)正文完