php從數(shù)據(jù)庫取數(shù)據(jù)顯示,php調(diào)用數(shù)據(jù)庫的值

如何用php獲取數(shù)據(jù)庫信息并顯示

獲取ppq數(shù)據(jù)庫的所有表名的代碼:

為海淀等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及海淀網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為做網(wǎng)站、網(wǎng)站制作、海淀網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

?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ù)組名,當獲取不到時

mysql_fetch_array()或者用mysql_fetch_row()返回

FALSE。

php中怎么從數(shù)據(jù)庫中取出數(shù)據(jù)?怎么顯示?最好有詳細的代碼

$con=mysql_connect('localhost','root','');//數(shù)據(jù)庫信息

mysql_select_db('shop');//數(shù)據(jù)庫名

mysql_query("set?names?utf8");//設置字符集編碼

$sql="select?goods_name,goods_number,shop_price?from?goods";//查詢語句

$res=mysql_query($sql);//執(zhí)行查詢

while($row=mysql_fetch_assoc($res)){

$rows[]=$row;//接受結(jié)果集

}

//遍歷數(shù)組

foreach($rows?as?$key=$v){

echo?$v['goods_name']."---".$v['goods_number']."---".$v['shop_price']."br/";

}

請問下怎么在PHP取數(shù)據(jù)庫中的一個字段的所有數(shù)據(jù)顯示在PHP頁面上?

兩種情況。

1、你剛學php沒有使用框架。每一個框架的的獲取數(shù)據(jù)的方法不一樣。他們功能的特點是都會配置數(shù)據(jù)連接,所以你只要按照他們的配置,進行配置就可以,一般要用戶名密碼,數(shù)據(jù)庫名。例如speed的位:

$spConfig = array(

'db' = array(

'host' = 'xxxx',

'login' = 'xxx',

'password' = 'xx',

'database' = 'xxx')

)

然后在模型(sql語句,指出表名,字段)中寫好表,以獲取。具體的學框架。寫出來太多了。

2、直接連接使用。我寫了點代碼如下:

$host ='';/主機

$login = '';//用戶

$password = '';//密碼

$database = '';//數(shù)據(jù)庫

$con = mysql_connect($host,$login,$password);

if(!$con)

{

die('could no neect'.mysql_error());

}

mysql_select_db($database,$con);

$result = mysql_query("select test from Test)//你的表

while($row = mysql_fetch_array($result))

{

echo $row[test];//字段名

}

mysql_close($con);

不懂再問!

如何正確理解PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)

1、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之 mysql_result()

mixed mysql_result(resource result_set, int row [,mixed field])

從result_set 的指定row 中獲取一個field 的數(shù)據(jù). 簡單但是效率低.

舉例:

$link1 = @mysql_connect("server1",

"webuser", "password")

or die("Could not connect

to mysql server!");

@mysql_select_db("company")

or die("Could not select database!");

$query = "select id, name

from product order by name";

$result = mysql_query($query);

$id = mysql_result($result, 0, "id");

$name = mysql_result($result, 0, "name");

mysql_close();

注意,上述代碼只是輸出結(jié)果集中的第一條數(shù)據(jù)的字段值,如果要輸出所有記錄,需要循環(huán)處理.

for ($i = 0; $i = mysql_num_rows($result); $i++)

{

$id = mysql_result($result, 0, "id");

$name = mysql_result($result, 0, "name");

echo "Product: $name ($id)";

}

注意,如果查詢字段名是別名,則mysql_result中就使用別名.

2、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_row()

array mysql_fetch_row(resource result_set)

從result_set中獲取整行,把數(shù)據(jù)放入數(shù)組中.

舉例(注意和list 的巧妙配合):

$query = "select id,

name from product order by name";

$result = mysql_query($query);

while(list($id, $name)

= mysql_fetch_row($result)) {

echo "Product: $name ($id)";

}

3、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_array()

array mysql_fetch_array(resource result_set [,int result_type])

mysql_fetch_row()的增強版.

將result_set的每一行獲取為一個關(guān)聯(lián)數(shù)組或/和數(shù)值索引數(shù)組.

默認獲取兩種數(shù)組,result_type可以設置:

MYSQL_ASSOC:返回關(guān)聯(lián)數(shù)組,字段名=字段值

MYSQL_NUM:返回數(shù)值索引數(shù)組.

MYSQL_BOTH:獲取兩種數(shù)組.因此每個字段可以按索引偏移引用,也可以按字段名引用.

舉例:

$query = "select id,

name from product order by name";

$result = mysql_query($query);

while($row = mysql_fetch_array

($result, MYSQL_BOTH)) {

$name = $row['name'];

//或者 $name = $row[1];

$name = $row['id'];

//或者 $name = $row[0];

echo "Product: $name ($id)";

}

4、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_assoc()

array mysql_fetch_assoc(resource result_set)

相當于 mysql_fetch_array($result, MYSQL_ASSOC)

5、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_object()

object mysql_fetch_object(resource result_set)

和mysql_fetch_array()功能一樣,不過返回的不是數(shù)組,而是一個對象.

舉例:

$query = "select id, name

from product order by name";

$result = mysql_query($query);

while($row = mysql_fetch_object

($result)) {

$name = $row-name;

$name = $row-id;

echo "Product: $name ($id)";

}

以上這些函數(shù)就是PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)的全部總結(jié)。

標題名稱:php從數(shù)據(jù)庫取數(shù)據(jù)顯示,php調(diào)用數(shù)據(jù)庫的值
當前路徑:http://muchs.cn/article10/hssddo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷商城網(wǎng)站、服務器托管、靜態(tài)網(wǎng)站、網(wǎng)站導航、企業(yè)網(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)

商城網(wǎng)站建設