本文目錄一覽:
怎麼用PHP語言來顯示MySQL資料庫內容
一般的結構如下:
?php
if (mysql_connect(‘127.0.0.1’, ‘root’, ‘123456’)){//注意密碼
$sql=’select * from try.ty limit 100′; //限制100,怕太多了
if ($res=mysql_query($sql)){
echo ‘table’;
while($row=mysql_fetch_row($res)){
echo ‘Trtd’. implode(‘td’,$row);
}
mysql_free_result($res);
echo ‘/table’;
}else ‘echo 執行資料庫查詢失敗,SQL語句:’.$sql.’br錯誤信息:’.mysql_error();
mysql_close();
}else echo ‘資料庫連接失敗,錯誤信息:’.mysql_error();
?
PHP如何讀取MYSQL並顯示出來
$conn=mysql_connect(‘localhost’,’root’,’root’) or die(“error connecting”) ;
mysql_query(“set names ‘utf8′”);
mysql_select_db(‘lxw’); //打開資料庫
$sql =”select id,pagename,isgroup,pagegroupid from author where id 20 order by isgroup desc”; //SQL語句
$result = mysql_query($sql,$conn); //查詢
while($row = mysql_fetch_array($result)){
}
mysql_close($conn); //關閉MySQL連接
給你推薦一個mysql操作類
medoo
如何在PHP中調用MYSQL數據並將其顯示在頁面中?
$conn=mysql_connect(‘localhost’,’username’,’userpassword’);
$db_selected = mysql_select_db(“你的資料庫名”,$conn);
$sql=”select * from pre_forum_forum where fid=xxx”;
$result=mysql_fetch_array(mysql_query($sql,$conn));
$result[‘posts’]就是你搖的值了。
怎麼用php顯示mysql 數據表數據
html
head
title瀏覽表中記錄/title
/head
body
center
?php
$db_host=localhost; //MYSQL伺服器名
$db_user=root; //MYSQL用戶名
$db_pass=””; //MYSQL用戶對應密碼
$db_name=”test”; //要操作的資料庫
//使用mysql_connect()函數對伺服器進行連接,如果出錯返回相應信息
$link=mysql_connect($db_host,$db_user,$db_pass)or die(“不能連接到伺服器”.mysql_error());
mysql_select_db($db_name,$link); //選擇相應的資料庫,這裡選擇test庫
$sql=”select * from test1″; //先執行SQL語句顯示所有記錄以與插入後相比較
$result=mysql_query($sql,$link); //使用mysql_query()發送SQL請求
echo “當前表中的記錄有:”;
echo “table border=1”; //使用表格格式化數據
echo “trtdID/tdtd姓名/tdtd郵箱/tdtd電話/tdtd地址/td/tr”;
while($row=mysql_fetch_array($result)) //遍歷SQL語句執行結果把值賦給數組
{
echo “tr”;
echo “td”.$row[id].”/td”; //顯示ID
echo “td”.$row[name].” /td”; //顯示姓名
echo “td”.$row[mail].” /td”; //顯示郵箱
echo “td”.$row[phone].” /td”; //顯示電話
echo “td”.$row[address].” /td”; //顯示地址
echo “/tr”;
}
echo “/table”;
?
/center
/body
/html
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/272076.html