當前位置:首頁 » 編程語言 » php資料庫函數

php資料庫函數

發布時間: 2023-03-02 10:39:30

A. php round函數用法是什麼

1、資料庫中的round()

Round函數返回一個數值,該數值是按照指定的小數位數進行四捨五入運算的結果。除數值外,也可對日期進行舍入運算。

2、Excel中的round()

round函數是EXCEL中的一個基本函數,作用按指定的位數對數值進行四捨五入,語法是ROUND(number, num_digits)。

3、PHP中的round()

round(x,prec),x:可選,規定要舍入的數字。prec:可選,規定小數點後的位數。

函數將返回將x根據指定精度prec(十進制小數點後數字的數目)進行四捨五入的結果。prec也可以是負數或零(默認值)。

B. 如何正確理解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")

ordie("Couldnotconnect
tomysqlserver!");

@mysql_select_db("company")
ordie("Couldnotselectdatabase!");

$query="selectid,name
fromproctorderbyname";

$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="selectid,
namefromproctorderbyname";

$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="selectid,
namefromproctorderbyname";

$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="selectid,name
fromproctorderbyname";

$result=mysql_query($query);

while($row=mysql_fetch_object
($result)){

$name=$row->name;

$name=$row->id;

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

}

以上這些函數就是PHP獲取顯示資料庫數據函數的全部總結。

C. PHP常用函數有哪些

常用函數比較多
如:字元串處理函數,數組函數,日期函數,MySQL函數,文件系統函數,GD函數庫等

D. 在PHP的mysqli擴展中,連接資料庫的函數是什麼

mysqli_connect,手冊上的例子如下圖:

E. PHP調用三種資料庫的方法(3)

Oracle(甲骨文)是世界上最為流行的關系資料庫。它是大公司推崇的工業化的強有力的引擎。我們先看看其相關的函數:
(1)integer
ora_logon(string
user
,
string
password)
開始對一個Oracle資料庫伺服器的連接。
(2)integer
ora_open(integer
connection)
打開給出的連接的游標。
(3)integer
ora_do(integer
connection,
string
query)
在給出的連接上執行查詢。PHP生成一個指示器,解析查詢,並執行之。
(4)integer
ora_parse(integer
cursor,
string
query)
解析一個查詢並准備好執行。
(5)boolean
ora_exec(integer
cursor)
執行一個先前由ora_parse函數解析過的查詢。
(6)boolean
ora_fetch(integer
cursor)
此函數會使得一個執行過的查詢中的行被取到指示器中。這使得您可以調用ora_getcolumn函數。
(7)string
ora_getcolumn(integer
cursor,
integer
column)
返回當前的值。列由零開始的數字索引。
(8)boolean
ora_logoff(integer
connection)
斷開對資料庫伺服器的鏈接。
以下是向ORACLE資料庫插入數據的示常式序:
<html>
<head><title>向ORACLE資料庫中插入數據</title></head>
<body>
<form
action="<?echo
$PHP_SELF;?>"
method="post">
<table
border="1"
cellspacing="0"
cellpadding="0">
<tr>
<th>ID</th>
<th>name</th>
<th>Description</th>
</tr>
<tr>
<td><input
type="text"
name="name"
maxlength="50"
size="10"></td>
<td><input
type="text"
name="email"
maxlength="255"
size="30"></td>
<td><input
type="text"
name="Description"
maxlength="255"
size="50"></td>
</tr>
<tr
align="center">
<td
colspan="3"><input
type="submit"
value="提交"> <input
type="reset"
value="重寫"></td>
</tr>
</table>
</form>
<?
//先設置兩個環境變數ORACLE_HOME,ORACLE_SID
putenv("ORACLE_HOME=/oracle/app/oracle/proct/8.0.4");
putenv("ORACLE_SID=ora8");
//設置網頁顯示中文
putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");
if($connection=ora_logon("scott","tiger"))
{
//庫表test有ID,name,Description三項
$sql
=
'insert
into
test(ID,name,Description)
values
';
$sql
.=
'(''
.
$ID
.
'',''
.
$name
.
'',''.
$Description
.
'')';
if($cursor=ora_do($connect,$sql))
{
print("insert
finished!");
}
$query
=
'select
*
from
test';
if($cursor=ora_do($connect,$query))
{
ora_fetch($cursor);
$content0=ora_getcolumn($cursor,0);
$content1=ora_getcolumn($cursor,1);
$content2=ora_getcolumn($cursor,2);
print("$content0");
print("$content1");
print("$content2");
ora_close($cursor);
}
ora_logoff($connection);
}
?>
</body>
</html>

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:593
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:888
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:582
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:765
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:684
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1013
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:255
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:114
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:806
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:713