代碼如下:?View
我們提供的服務(wù)有:網(wǎng)站設(shè)計(jì)、做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、臺(tái)兒ssl等。為上1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的臺(tái)兒網(wǎng)站制作公司
Code
PHP
include("conn.php");//調(diào)用數(shù)據(jù)庫(kù)連接文件
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查詢語(yǔ)句
while
($row
=
mysql_fetch_array($query)){
//使用while循環(huán)mysql_fetch_array()并將數(shù)據(jù)返回?cái)?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";輸出記錄截圖
先配置數(shù)據(jù)庫(kù)------連接數(shù)據(jù)庫(kù)--------選擇數(shù)據(jù)庫(kù)--------填寫檢索表-------輸出檢索內(nèi)容
第一種解決方法:
一、配置一下數(shù)據(jù)庫(kù):
define("DB_HOST","localhost");//數(shù)據(jù)庫(kù)地址,一般為localhost
define("DB_USER","root");//數(shù)據(jù)庫(kù)用戶名
define("DB_PSW","");//數(shù)據(jù)庫(kù)密碼
define("DB_DB","databasename");//需要操作的數(shù)據(jù)庫(kù)
二、連接數(shù)據(jù)庫(kù):
$conn = mysql_connect(DB_HOST,DB_USER,DB_PSW) or die
三、選擇數(shù)據(jù)庫(kù):
mysql_select_db(DB_DB,$conn) or die
四、檢索表:(填寫tablename)
$result = mysql_query("select * from tablename") or die
五、輸出檢索的內(nèi)容:
while ($row = mysql_fetch_row($result)){foreach($row as $data){ ? ?echo $data.' ';} ? ?echo 'br。
獲取ppq數(shù)據(jù)庫(kù)的所有表名的代碼:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("數(shù)據(jù)庫(kù)系統(tǒng)連接失??!");
$result=mysql_list_tables($dbname);
if(!$result)
die("數(shù)據(jù)庫(kù)連接失?。?);
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ù)庫(kù)中的表
說(shuō)明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個(gè)數(shù)據(jù)庫(kù)名并返回和
mysql_query()
函數(shù)很相似的一個(gè)結(jié)果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來(lái)獲得一個(gè)數(shù)組,數(shù)組的第0列就是數(shù)組名,當(dāng)獲取不到時(shí)
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
進(jìn)入php源程序目錄中的ext目錄中,這里存放著各個(gè)擴(kuò)展模塊的源代碼,選擇你需要的模塊,比如curl模塊:cd curl
執(zhí)行phpize生成編譯文件,phpize在PHP安裝目錄的bin目錄下
/usr/local/php5/bin/phpize
運(yùn)行時(shí),可能會(huì)報(bào)錯(cuò):Cannot find autoconf. Please check your autoconf installation and
the $PHP_AUTOCONF
environment variable is set correctly and then rerun this
script.,需要安裝autoconf:
yum install autoconf(RedHat或者CentOS)、apt-get install
autoconf(Ubuntu Linux)
/usr/local/php5/bin/php -v
執(zhí)行這個(gè)命令時(shí),php會(huì)去檢查配置文件是否正確,如果有配置錯(cuò)誤,
這里會(huì)報(bào)錯(cuò),可以根據(jù)錯(cuò)誤信息去排查!
大概的基本流程如下:
連接數(shù)據(jù)庫(kù),再加一個(gè)判斷。
選擇數(shù)據(jù)庫(kù)
讀取表
輸出表中數(shù)據(jù)
下面是代碼:
?php
$con = mysql_connect("localhost","root","abc123");
/* localhost 是服務(wù)器 root 是用戶名?abc123 是密碼*/?
if (!$con)
{
die("數(shù)據(jù)庫(kù)服務(wù)器連接失敗");
}
/*?這就是一個(gè)邏輯非判斷,如果錯(cuò)誤就輸出括號(hào)里的字符串 */?
@mysql_select_db("a",?$con);?
/*?選擇mysql服務(wù)器里的一個(gè)數(shù)據(jù)庫(kù),假設(shè)你的數(shù)據(jù)庫(kù)名為?a*/
$sql?=?"SELECT?*?FROM qq";?
/* 定義變量sql,?"SELECT?*?FROM?qq" 是SQL指令,表示選取表qq中的數(shù)據(jù)?*/
$result = mysql_query($sql); //執(zhí)行SQL語(yǔ)句,獲得結(jié)果集
/*下面就是選擇性的輸出打印了,由于不清楚你的具體情況給你個(gè)表格打印吧*/
//打印表格?
echo "table border=1";?
while( $row = mysql_fetch_array($result) )
/*逐行獲取結(jié)果集中的記錄,得到數(shù)組row?*/
{ ?
/*數(shù)組row的下標(biāo)對(duì)應(yīng)著數(shù)據(jù)庫(kù)中的字段值?*/
$id = $row['id'];?
$name = $row['name'];?
$sex = $row['sex'];?
echo "tr";?
echo "td$id/td";?
echo "td$name/td";?
echo "td$sex/td";?
echo "/tr";?
}?
echo "table /";
?
如果你的switch是表頭,就定義這個(gè)表頭字段,然后輸出。
當(dāng)前題目:php獲取電商數(shù)據(jù)庫(kù) 一個(gè)完整的電商數(shù)據(jù)庫(kù)
標(biāo)題URL:http://muchs.cn/article40/hphdho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、App設(shè)計(jì)、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、軟件開發(fā)、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)