本文目錄一覽:
- 1、php+mysql如何讀取資料庫數據?
- 2、php如何獲取資料庫信息
- 3、php如何取資料庫中內容
- 4、怎樣藉助PHP從HTML網頁中獲取phpmyadmin資料庫里數據表的內容
- 5、如何用php獲取資料庫信息並顯示
php+mysql如何讀取資料庫數據?
先配置資料庫——連接資料庫——–選擇資料庫——–填寫檢索表——-輸出檢索內容
第一種解決方法:
一、配置一下資料庫:
define(“DB_HOST”,”localhost”);//資料庫地址,一般為localhost
define(“DB_USER”,”root”);//資料庫用戶名
define(“DB_PSW”,””);//資料庫密碼
define(“DB_DB”,”databasename”);//需要操作的資料庫
二、連接資料庫:
$conn = mysql_connect(DB_HOST,DB_USER,DB_PSW) or die
三、選擇資料庫:
mysql_select_db(DB_DB,$conn) or die
四、檢索表:(填寫tablename)
$result = mysql_query(“select * from tablename”) or die
五、輸出檢索的內容:
while ($row = mysql_fetch_row($result)){foreach($row as $data){ echo $data.’ ‘;} echo ‘br。
php如何獲取資料庫信息
代碼如下:?View
Code
PHP
include(“conn.php”);//調用資料庫連接文件
echo
“table
width=572
height=56
border=0
cellspacing=1
“;
//創建html表格
echo
“tr
bgcolor=#9999FF”;
echo
“th
width=33
scope=colid/th”;
echo
“th
width=100
scope=coluser_name/th
“;
echo
“th
width=100
scope=coluser_pass/th
“;
echo
“th
width=100
scope=colstaus/th”;
echo
“th
width=100
scope=colinsert_time/th”;
echo
“/tr”;
$SQL
=
“select
*
from
user_info”;
$query
=
mysql_query($SQL);
//SQL查詢語句
while
($row
=
mysql_fetch_array($query)){
//使用while循環mysql_fetch_array()並將數據返回數組
echo
“tr
onmouseout=this.style.backgroundColor=”
onMouseOver=this.style.backgroundColor=’#99CC33′
bgcolor=#CCCCCC”;
echo
“td$row[0]/td”;
//輸出數組中數據
echo
“td$row[1]/td”;
echo
“td$row[2]/td”;
echo
“td$row[3]/td”;
echo
“td$row[4]/td”;
echo
“/tr”;
}
echo
“/table”;輸出記錄截圖
php如何取資料庫中內容
試編寫代碼如下:
?php
//從資料庫根據 id 獲取顏色
function getColor($db, $id)
{
if ($result = $db-query(“SELECT * FROM color where id='” . $id . “‘”))
{
$row = $result-fetch_assoc();
return $row[‘color’];
}
return ‘#000000’;
}
$mysqli = new mysqli(“localhost”, “test”, “test”, “room”);
if ($mysqli-connect_error) {
printf(“資料庫連接錯誤: %s\n”, mysqli_connect_error());
exit();
}
?
table border=”1″ cellspacing=”0″
tr
td bgcolor=”?php echo getColor($mysqli,’1′)?”1/td
/tr
tr
td bgcolor=”?php echo getColor($mysqli,’2′)?”2/td
/tr
tr
td bgcolor=”?php echo getColor($mysqli,’3′)?”3/td
/tr
/table
?php
$mysqli-close();
?
怎樣藉助PHP從HTML網頁中獲取phpmyadmin資料庫里數據表的內容
?php
$link=mysql_connect(‘localhost’,’用戶名’,’密碼’)or die(“資料庫連接失敗”);//連接資料庫
mysql_select_db(‘資料庫名’,$link);//選擇資料庫
mysql_query(“set names utf8”);//設置編碼格式
$q=”select * from “數據表”;//設置查詢指令
$result=mysql_query($q);//執行查詢
while($row=mysql_fetch_assoc($result))//將result結果集中查詢結果取出一條
{ echo 返回到HTML; }
?
html界面使用ajax的成功返回值,再渲染在界面里就行了
如何用php獲取資料庫信息並顯示
獲取ppq資料庫的所有表名的代碼:
?php
$server=’localhost’;
$user=’root’;
$pass=’12345′;
$dbname=’ppq’;
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die(“資料庫系統連接失敗!”);
$result=mysql_list_tables($dbname);
if(!$result)
die(“資料庫連接失敗!”);
while($row=mysql_fetch_row($result))
{
echo
$row[0].”
“;
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
—
列出
MySQL
資料庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個資料庫名並返回和
mysql_query()
函數很相似的一個結果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個數組,數組的第0列就是數組名,當獲取不到時
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/219761.html