獲取ppq數(shù)據(jù)庫的所有表名的代碼:
磁縣ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("數(shù)據(jù)庫系統(tǒng)連接失敗!");
$result=mysql_list_tables($dbname);
if(!$result)
die("數(shù)據(jù)庫連接失敗!");
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
數(shù)據(jù)庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個數(shù)據(jù)庫名并返回和
mysql_query()
函數(shù)很相似的一個結(jié)果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個數(shù)組,數(shù)組的第0列就是數(shù)組名,當(dāng)獲取不到時
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
試編寫代碼如下:
?php
//從數(shù)據(jù)庫根據(jù)?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("數(shù)據(jù)庫連接錯誤:?%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();
?
連接到一個?url?地址為localhost?、?端口為?3306?的mysql服務(wù)器上。mysql服務(wù)器的帳號是"root",密碼是"9999"。mysql?服務(wù)器上有一個數(shù)據(jù)庫?ok?,?數(shù)據(jù)庫里有一個表?abc。表?abc?一共為兩列,列名分別是?"id"?和?"name"?,將?abc?里的所有數(shù)據(jù)讀出來。
??
$dbh?=?@mysql_connect("localhost:3306","root","9999");?
/*?定義變量dbh?,?mysql_connect()函數(shù)的意思是連接mysql數(shù)據(jù)庫,?"@"的意思是屏蔽報錯?*/?
if(!$dbh){die("error");}?
/*?die()函數(shù)的意思是將括號里的字串送到瀏覽器并中斷PHP程式?(Script)。括號里的參數(shù)為欲送出的字串。?*/?
@mysql_select_db("ok",?$dbh);?
/*?選擇mysql服務(wù)器里的一個數(shù)據(jù)庫,這里選的數(shù)據(jù)庫名為?ok?*/?
$q?=?"SELECT?*?FROM?abc";?
/*?定義變量q,?"SELECT?*?FROM?abc"是一個SQL語句,意思是讀取表abc中的數(shù)據(jù)?*/?
??
br?/?
!--=========?方法一?=========--?
br?/?
??
$rs?=?mysql_query($q,?$dbh);?
/*?定義變量?rs?,函數(shù)mysql_query()的意思是:送出?query?字串供?MySQL?做相關(guān)的處理或者執(zhí)行.由于php是從右往左執(zhí)行的,所以,rs的值是服務(wù)器運行mysql_query()函數(shù)后返回的值?*/?
if(!$rs){die("Valid?result!");}?
echo?"table";?
echo?"trtdID/tdtdName/td/tr";?
while($row?=?mysql_fetch_row($rs))?echo?"trtd$row[0]/tdtd$row[1]/td/tr";?
/*?定義量變(數(shù)組)row,并利用while循環(huán),把數(shù)據(jù)一一寫出來.??
函數(shù)mysql_fetch_row()的意思是:將查詢結(jié)果$rs單列拆到陣列變數(shù)中.??
$row[0]?和?$row[1]?的位置可以換*/?
echo?"/table";?
??
br?/?
!--=========?方法二?=========--?
br?/?
??
$rs?=?mysql_query($q,?$dbh);?
while($row?=?mysql_fetch_object($rs))?echo?"$row-id?$row-name?br?/";?
/*?id和name可以換位置?*/?
??
br?/?
!--=========?方法三?=========--?
br?/?
??
$rs?=?mysql_query($q,?$dbh);?
while($row?=?mysql_fetch_array($rs))?echo?"$row[id]?$row[name]?br?/";?
/*?id和name可以換位置?*/?
??
!--=========?方法三最快?=========--?
??
@mysql_close($dbh);?
/*?關(guān)閉到mysql數(shù)據(jù)庫的連接?*/?
?
代碼如下:?View
Code
PHP
include("conn.php");//調(diào)用數(shù)據(jù)庫連接文件
echo
"table
width=572
height=56
border=0
cellspacing=1
";
//創(chuàng)建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循環(huán)mysql_fetch_array()并將數(shù)據(jù)返回數(shù)組
echo
"tr
onmouseout=this.style.backgroundColor=''
onMouseOver=this.style.backgroundColor='#99CC33'
bgcolor=#CCCCCC";
echo
"td$row[0]/td";
//輸出數(shù)組中數(shù)據(jù)
echo
"td$row[1]/td";
echo
"td$row[2]/td";
echo
"td$row[3]/td";
echo
"td$row[4]/td";
echo
"/tr";
}
echo
"/table";輸出記錄截圖
1.看看密碼是否被加密。
2.list($key,$value)=each($arr);
!!是 list($Uname,$Pwd)=mysql_fetch_row($result); 的錯誤:
mysql_fetch_row($result) 返回一個數(shù)組
正確格式是:list($Uname,$Pwd)=each(mysql_fetch_row($result));
分享題目:php數(shù)據(jù)庫中采集信息,php數(shù)據(jù)庫中采集信息的函數(shù)
本文鏈接:http://chinadenli.net/article48/hdoeep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計公司、虛擬主機(jī)、用戶體驗、品牌網(wǎng)站建設(shè)、Google、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)