?php
我們提供的服務有:成都網(wǎng)站設(shè)計、網(wǎng)站制作、外貿(mào)營銷網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、潮州ssl等。為近千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術(shù)的潮州網(wǎng)站制作公司
//建立數(shù)據(jù)庫鏈接,
mysql_connect("localhost",?"mysql_user",?"mysql_password")?or
die("Could?not?connect:?"?.?mysql_error());
//選擇數(shù)據(jù)庫
mysql_select_db("mydb");
//查詢sql語句
$result?=?mysql_query("SELECT?id,?name?FROM?mytable");
//輸出查詢結(jié)果
while?($row?=?mysql_fetch_array($result))?{
echo?$row['id']?,"br?/",?$row['name'];??
}
//釋放結(jié)果內(nèi)存
mysql_free_result($result);
?
Oracle(甲骨文)是世界上最為流行的關(guān)系數(shù)據(jù)庫。它是大公司推崇的工業(yè)化的強有力的引擎。我們先看看其相關(guān)的函數(shù):
(1)integer
ora_logon(string
user
,
string
password)
開始對一個Oracle數(shù)據(jù)庫服務器的連接。
(2)integer
ora_open(integer
connection)
打開給出的連接的游標。
(3)integer
ora_do(integer
connection,
string
query)
在給出的連接上執(zhí)行查詢。PHP生成一個指示器,解析查詢,并執(zhí)行之。
(4)integer
ora_parse(integer
cursor,
string
query)
解析一個查詢并準備好執(zhí)行。
(5)boolean
ora_exec(integer
cursor)
執(zhí)行一個先前由ora_parse函數(shù)解析過的查詢。
(6)boolean
ora_fetch(integer
cursor)
此函數(shù)會使得一個執(zhí)行過的查詢中的行被取到指示器中。這使得您可以調(diào)用ora_getcolumn函數(shù)。
(7)string
ora_getcolumn(integer
cursor,
integer
column)
返回當前的值。列由零開始的數(shù)字索引。
(8)boolean
ora_logoff(integer
connection)
斷開對數(shù)據(jù)庫服務器的鏈接。
以下是向ORACLE數(shù)據(jù)庫插入數(shù)據(jù)的示例程序:
html
headtitle向ORACLE數(shù)據(jù)庫中插入數(shù)據(jù)/title/head
body
form
action="?echo
$PHP_SELF;?"
method="post"
table
border="1"
cellspacing="0"
cellpadding="0"
tr
thID/th
thname/th
thDescription/th
/tr
tr
tdinput
type="text"
name="name"
maxlength="50"
size="10"/td
tdinput
type="text"
name="email"
maxlength="255"
size="30"/td
tdinput
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
?
//先設(shè)置兩個環(huán)境變量ORACLE_HOME,ORACLE_SID
putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");
putenv("ORACLE_SID=ora8");
//設(shè)置網(wǎng)頁顯示中文
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
連接到一個?url?地址為localhost?、?端口為?3306?的mysql服務器上。mysql服務器的帳號是"root",密碼是"9999"。mysql?服務器上有一個數(shù)據(jù)庫?ok?,?數(shù)據(jù)庫里有一個表?abc。表?abc?一共為兩列,列名分別是?"id"?和?"name"?,將?abc?里的所有數(shù)據(jù)讀出來。
??
$dbh?=?@mysql_connect("localhost:3306","root","9999");?
/*?定義變量dbh?,?mysql_connect()函數(shù)的意思是連接mysql數(shù)據(jù)庫,?"@"的意思是屏蔽報錯?*/?
if(!$dbh){die("error");}?
/*?die()函數(shù)的意思是將括號里的字串送到瀏覽器并中斷PHP程式?(Script)。括號里的參數(shù)為欲送出的字串。?*/?
@mysql_select_db("ok",?$dbh);?
/*?選擇mysql服務器里的一個數(shù)據(jù)庫,這里選的數(shù)據(jù)庫名為?ok?*/?
$q?=?"SELECT?*?FROM?abc";?
/*?定義變量q,?"SELECT?*?FROM?abc"是一個SQL語句,意思是讀取表abc中的數(shù)據(jù)?*/?
??
br?/?
!--=========?方法一?=========--?
br?/?
??
$rs?=?mysql_query($q,?$dbh);?
/*?定義變量?rs?,函數(shù)mysql_query()的意思是:送出?query?字串供?MySQL?做相關(guān)的處理或者執(zhí)行.由于php是從右往左執(zhí)行的,所以,rs的值是服務器運行mysql_query()函數(shù)后返回的值?*/?
if(!$rs){die("Valid?result!");}?
echo?"table";?
echo?"trtdID/tdtdName/td/tr";?
while($row?=?mysql_fetch_row($rs))?echo?"trtd$row[0]/tdtd$row[1]/td/tr";?
/*?定義量變(數(shù)組)row,并利用while循環(huán),把數(shù)據(jù)一一寫出來.??
函數(shù)mysql_fetch_row()的意思是:將查詢結(jié)果$rs單列拆到陣列變數(shù)中.??
$row[0]?和?$row[1]?的位置可以換*/?
echo?"/table";?
??
br?/?
!--=========?方法二?=========--?
br?/?
??
$rs?=?mysql_query($q,?$dbh);?
while($row?=?mysql_fetch_object($rs))?echo?"$row-id?$row-name?br?/";?
/*?id和name可以換位置?*/?
??
br?/?
!--=========?方法三?=========--?
br?/?
??
$rs?=?mysql_query($q,?$dbh);?
while($row?=?mysql_fetch_array($rs))?echo?"$row[id]?$row[name]?br?/";?
/*?id和name可以換位置?*/?
??
!--=========?方法三最快?=========--?
??
@mysql_close($dbh);?
/*?關(guān)閉到mysql數(shù)據(jù)庫的連接?*/?
?
網(wǎng)頁名稱:php調(diào)取數(shù)據(jù)庫,php獲取數(shù)據(jù)庫
文章源于:http://muchs.cn/article10/hciigo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、電子商務、網(wǎng)站制作、定制開發(fā)、響應式網(wǎng)站、網(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)