當前位置:首頁 » 數據倉庫 » php獲取資料庫類型
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

php獲取資料庫類型

發布時間: 2022-11-20 09:17:55

Ⅰ 如何正確理解PHP獲取顯示資料庫數據函數

1、PHP獲取顯示資料庫數據函數之 mysql_result()
mixed mysql_result(resource result_set, int row [,mixed field])
從result_set 的指定row 中獲取一個field 的數據. 簡單但是效率低.
舉例:
$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 proct order by name";
$result = mysql_query($query);
$id = mysql_result($result, 0, "id");
$name = mysql_result($result, 0, "name");
mysql_close();
注意,上述代碼只是輸出結果集中的第一條數據的欄位值,如果要輸出所有記錄,需要循環處理.

for ($i = 0; $i <= mysql_num_rows($result); $i++)
{
$id = mysql_result($result, 0, "id");
$name = mysql_result($result, 0, "name");
echo "Proct: $name ($id)";
}
注意,如果查詢欄位名是別名,則mysql_result中就使用別名.

2、PHP獲取顯示資料庫數據函數之mysql_fetch_row()
array mysql_fetch_row(resource result_set)
從result_set中獲取整行,把數據放入數組中.
舉例(注意和list 的巧妙配合):

$query = "select id,
name from proct order by name";
$result = mysql_query($query);
while(list($id, $name)
= mysql_fetch_row($result)) {
echo "Proct: $name ($id)";
}

3、PHP獲取顯示資料庫數據函數之mysql_fetch_array()
array mysql_fetch_array(resource result_set [,int result_type])
mysql_fetch_row()的增強版.
將result_set的每一行獲取為一個關聯數組或/和數值索引數組.
默認獲取兩種數組,result_type可以設置:
MYSQL_ASSOC:返回關聯數組,欄位名=>欄位值
MYSQL_NUM:返回數值索引數組.
MYSQL_BOTH:獲取兩種數組.因此每個欄位可以按索引偏移引用,也可以按欄位名引用.
舉例:

$query = "select id,
name from proct 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 "Proct: $name ($id)";
}

4、PHP獲取顯示資料庫數據函數之mysql_fetch_assoc()
array mysql_fetch_assoc(resource result_set)
相當於 mysql_fetch_array($result, MYSQL_ASSOC)

5、PHP獲取顯示資料庫數據函數之mysql_fetch_object()
object mysql_fetch_object(resource result_set)
和mysql_fetch_array()功能一樣,不過返回的不是數組,而是一個對象.
舉例:

$query = "select id, name
from proct order by name";
$result = mysql_query($query);
while($row = mysql_fetch_object
($result)) {
$name = $row->name;
$name = $row->id;
echo "Proct: $name ($id)";
}
以上這些函數就是PHP獲取顯示資料庫數據函數的全部總結。

Ⅱ php 如何獲取mysql bigint類型數據

php 獲取數據是不需要寫類型的,你可以看下邊的例子:
$name="張三"; //這種就是字元串
$age=2; //這種就是數字
$other=array("123",22); //數組
像這些,你定義的什麼類型,php就可以接受什麼類型。不需要特意轉

Ⅲ 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=col>id</th>";
echo
"<th
width=100
scope=col>user_name</th>
";
echo
"<th
width=100
scope=col>user_pass</th>
";
echo
"<th
width=100
scope=col>staus</th>";
echo
"<th
width=100
scope=col>insert_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 怎麼POST獲取數據

方法1、最常見的方法是:$_post['fieldname'];
說明:只能接收content-type:
application/x-www-form-urlencoded提交的數據
解釋:也就是表單post過來的數據
方法2、file_get_contents("php://input");
說明:
允許讀取
post
的原始數據。

$http_raw_post_data
比起來,它給內存帶來的壓力較小,並且不需要任何特殊的
php.ini
設置。
php://input
不能用於
enctype="multipart/form-data"。
解釋:
對於未指定
content-type
的post數據,則可以使用file_get_contents(「php://input」);來獲取原始數據。
事實上,用php接收post的任何數據都可以使用本方法。而不用考慮content-type,包括二進制文件流也可以。
所以用方法二是最保險的方法

Ⅳ php 獲取 sql 數據類型

describetablename;//獲取表結構信息
describetablenamefieldname;//獲取表的某個欄位結構信息
比如:describeusersusername;//獲取users表的username欄位的結構信息
返回:array(
'Field'=>'username',
'Type'=>'varchar(50)',
'Null'=>'NO',
'Key'=>'UNI',
'Default'=>'',
'Extra'=>''
)

Ⅵ php pdo 如何獲取查詢資料庫

$qian["qian"]=$qian["qian"]->DBSQL("select*fromuserwhere='$name'");

多命名幾個變數,你這樣 `$qian["qian"]` 用在不同的類型中,容易搞混。

$db=newDatabase();
$result=$db->DBSQL("select*fromuserwhere='$name'limit1");

這里的 $result 應該是個數組。

if($result['qian']==1){
//
}else{
//
}

Ⅶ 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=col>id</th>"; echo "<th width=100 scope=col>user_name</th> "; echo "<th width=100 scope=col>user_pass</th> "; echo "<th width=100 scope=col>staus</th>"; echo "<th width=100 scope=col>insert_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程序去監控要執行的PHP程序嗎?應該無法做得到的吧,你通過看連接資料庫的代碼就可以知道使用的是什麼資料庫啊。

那更好處理啊,你如何判斷用什麼語法連接資料庫就輸出什麼類型資料庫不就行啦

Ⅸ php框架thinkphp3.2怎麼讀取資料庫內容

先找到config.php文件,如圖:

<?php
namespaceHomeController;
useThinkController;
{
publicfunctionindex(){
$db=M("show");//實例化show對象
$data=$db->find();//讀取一條數據
mp($data);//列印數據
}
}

Ⅹ php支持哪些數據類型

php的數據類型有:1、String字元串型;2、Integer整型;3、Float和Double浮點型;4、Boolean布爾型;5、Array數組;6、Object對象;7、NULL空值等等。