代碼如下:?View
創(chuàng)新互聯(lián)于2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術服務公司,擁有項目成都網(wǎng)站制作、做網(wǎng)站網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元順慶做網(wǎng)站,已為上家服務,為順慶各地企業(yè)和個人服務,聯(lián)系電話:13518219792
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";輸出記錄截圖
獲取ppq數(shù)據(jù)庫的所有表名的代碼:
?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ù)很相似的一個結果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個數(shù)組,數(shù)組的第0列就是數(shù)組名,當獲取不到時
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
需要準備的材料分別是:電腦、php編輯器、瀏覽器。
1、首先,打開php編輯器,新建php文件,例如:index.php,以獲取user表name字段為例。
2、在index.php中,輸入代碼:$User = M("User");$data = $User-field(['name'])-find();print_r($data);。
3、瀏覽器運行index.php頁面,此時會打印出user表name字段的查詢結果。
大概的基本流程如下:
連接數(shù)據(jù)庫,再加一個判斷。
選擇數(shù)據(jù)庫
讀取表
輸出表中數(shù)據(jù)
下面是代碼:
?php
$con = mysql_connect("localhost","root","abc123");
/* localhost 是服務器 root 是用戶名?abc123 是密碼*/?
if (!$con)
{
die("數(shù)據(jù)庫服務器連接失敗");
}
/*?這就是一個邏輯非判斷,如果錯誤就輸出括號里的字符串 */?
@mysql_select_db("a",?$con);?
/*?選擇mysql服務器里的一個數(shù)據(jù)庫,假設你的數(shù)據(jù)庫名為?a*/
$sql?=?"SELECT?*?FROM qq";?
/* 定義變量sql,?"SELECT?*?FROM?qq" 是SQL指令,表示選取表qq中的數(shù)據(jù)?*/
$result = mysql_query($sql); //執(zhí)行SQL語句,獲得結果集
/*下面就是選擇性的輸出打印了,由于不清楚你的具體情況給你個表格打印吧*/
//打印表格?
echo "table border=1";?
while( $row = mysql_fetch_array($result) )
/*逐行獲取結果集中的記錄,得到數(shù)組row?*/
{ ?
/*數(shù)組row的下標對應著數(shù)據(jù)庫中的字段值?*/
$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是表頭,就定義這個表頭字段,然后輸出。
要用javascript調(diào)用php獲取數(shù)據(jù)庫接口,是一個很常見的前后端交互操作
通過javascript發(fā)送http請求php的API接口,php連接數(shù)據(jù)庫并查詢結果,最后返回出來
這樣javascript就能獲取到數(shù)據(jù)庫的數(shù)據(jù)
本文標題:php獲取數(shù)據(jù)庫數(shù)據(jù),php查詢數(shù)據(jù)庫數(shù)據(jù)返回數(shù)據(jù)
轉載來源:http://www.muchs.cn/article20/hcphjo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化、網(wǎng)站改版、定制網(wǎng)站、關鍵詞優(yōu)化、電子商務、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)