真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

php數(shù)據(jù)庫方法嗎,php可以支持目前主流的數(shù)據(jù)庫

PHP調(diào)用三種數(shù)據(jù)庫的方法(3)

Oracle(甲骨文)是世界上最為流行的關(guān)系數(shù)據(jù)庫。它是大公司推崇的工業(yè)化的強(qiáng)有力的引擎。我們先看看其相關(guān)的函數(shù):

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、城固網(wǎng)絡(luò)推廣、小程序設(shè)計(jì)、城固網(wǎng)絡(luò)營銷、城固企業(yè)策劃、城固品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供城固建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com

(1)integer

ora_logon(string

user

,

string

password)

開始對(duì)一個(gè)Oracle數(shù)據(jù)庫服務(wù)器的連接。

(2)integer

ora_open(integer

connection)

打開給出的連接的游標(biāo)。

(3)integer

ora_do(integer

connection,

string

query)

在給出的連接上執(zhí)行查詢。PHP生成一個(gè)指示器,解析查詢,并執(zhí)行之。

(4)integer

ora_parse(integer

cursor,

string

query)

解析一個(gè)查詢并準(zhǔn)備好執(zhí)行。

(5)boolean

ora_exec(integer

cursor)

執(zhí)行一個(gè)先前由ora_parse函數(shù)解析過的查詢。

(6)boolean

ora_fetch(integer

cursor)

此函數(shù)會(huì)使得一個(gè)執(zhí)行過的查詢中的行被取到指示器中。這使得您可以調(diào)用ora_getcolumn函數(shù)。

(7)string

ora_getcolumn(integer

cursor,

integer

column)

返回當(dāng)前的值。列由零開始的數(shù)字索引。

(8)boolean

ora_logoff(integer

connection)

斷開對(duì)數(shù)據(jù)庫服務(wù)器的鏈接。

以下是向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è)置兩個(gè)環(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三項(xiàng)

$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

PHP連接數(shù)據(jù)庫的幾種方法

用ASP連接各種數(shù)據(jù)庫的方法

一、ASP的對(duì)象存取數(shù)據(jù)庫方法

在ASP中,用來存取數(shù)據(jù)庫的對(duì)象統(tǒng)稱ADO(Active Data Objects),主要含有三種對(duì)象:Connection、Recordset 、Command

Connection:負(fù)責(zé)打開或連接數(shù)據(jù)

Recordset:負(fù)責(zé)存取數(shù)據(jù)表

Command:負(fù)責(zé)對(duì)數(shù)據(jù)庫執(zhí)行行動(dòng)查詢命令

二、連接各數(shù)據(jù)庫的驅(qū)動(dòng)程序

連接各數(shù)據(jù)庫可以使用驅(qū)動(dòng)程序,也可以使用數(shù)據(jù)源,不過我建議大家使用驅(qū)動(dòng)程序,因?yàn)槭褂抿?qū)動(dòng)程序非常方便、簡(jiǎn)單,而使用數(shù)據(jù)源比較麻煩。

ODBC鏈接

適合數(shù)據(jù)庫類型 鏈接方式

access "Driver={microsoft access driver(*.mdb)};dbq=*.mdb;uid=admin;pwd=pass;"

dBase "Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq=------------;"

Oracle "Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;"

MSSQL server "Driver={sql server};server=servername;database=dbname;uid=sa;pwd=pass;"

MS text "Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;extensions=asc,csv,tab,txt;Persist SecurityInfo=false;"

Visual Foxpro "Driver={microsoft Visual Foxpro driver};sourcetype=DBC;sourceDB=*.dbc;Exclusive=No;"

MySQL "Driver={mysql};database=yourdatabase;uid=username;pwd=yourpassword;option=16386;"

OLEDB鏈接

適合的數(shù)據(jù)庫類型 鏈接方式

access "Provider=microsoft.jet.oledb.4.0;data source=your_database_path;user id=admin;password=pass;"

Oracle "Provider=OraOLEDB.Oracle;data source=dbname;user id=admin;password=pass;"

MS SQL Server "Provider=SQLOLEDB;data source=machinename;initial catalog=dbname;userid=sa;password=pass;"

MS text "Provider=microsof.jet.oledb.4.0;data source=your_path;Extended Properties′text;FMT=Delimited′"

而我們?cè)谝话闱闆r下使用Access的數(shù)據(jù)庫比較多,在這里我建議大家連接Access數(shù)據(jù)庫使用下面的方法:

dim conn

set conn = server.createobject("adodb.connection")

conn.open = "provider=microsoft.jet.oledb.4.0;" "data source = " server.mappath("../db/bbs.mdb")

其中../db/bbs.mdb是你的數(shù)據(jù)庫存放的相對(duì)路徑!如果你的數(shù)據(jù)庫和ASP文件在同一目錄下,你只要這樣寫就可以了:

dim conn

set conn = server.createobject("adodb.connection")

conn.open = "provider=microsoft.jet.oledb.4.0;" "data source = " server.mappath("bbs.mdb")

有許多初學(xué)者在遇到數(shù)據(jù)庫連接時(shí)總是會(huì)出問題,然而使用上面的驅(qū)動(dòng)程序只要你的數(shù)據(jù)庫路徑選對(duì)了就不會(huì)出問題了。

PHP7連接mysql數(shù)據(jù)庫方法

1、用 mysql_connect 的方法,PHP7會(huì)報(bào)致命錯(cuò)誤

$conn= mysql_connect('localhost','xueyanxiang','xueyanxiang');

Fatal error : Uncaught Error: Call to undefined function mysql_connect() in /Users/xueyanxiang/work/test/xue.php:31 Stack trace: #0 /Users/xueyanxiang/work/test/xue.php(119): xue-run() #1 {main} thrown in? /Users/xueyanxiang/work/test/xue.php ?on line? 31

原因是:

PHP5中使用mysql_connect()函數(shù)進(jìn)行連接,但實(shí)際上,PHP5.5開始,MySQL就不推薦使用了,屬于廢棄函數(shù)

PHP7中貌似已經(jīng)徹底不支持了,根據(jù)官網(wǎng)說明,取而代之的是如下兩個(gè):

本擴(kuò)展自 PHP 5.5.0 起已廢棄,并在將來會(huì)被移除。應(yīng)使用?MySQLi?或?PDO_MySQL?擴(kuò)展來替換之。參見?MySQL:選擇

API?指南以及相關(guān) FAQ?以獲取更多信息。用以替代本函數(shù)的有:

mysqli_connect()

PDO::__construct()

使用時(shí),不要在使用mysql_connect了,可以換用mysqli_connect(),用法基本類似吧,據(jù)說是面向?qū)ο蟮膸臁?/p>

php.ini中,也只有extension=php_mysqli.dll,而不再有extension=php_mysql.dll這個(gè)拓展了。

2、可以使用mysqli,對(duì)象化,方法名與被廢棄的類似

$conn= mysqli_connect('localhost','xueyanxiang','xueyanxiang');

3、PDO工具,推薦使用

$dbh= "mysql:host=localhost;dbname=test";

$db= new PDO($dbh,'xueyanxiang','xueyanxiang');

$objQuery= $db-query("select * from user;");

$res= $objQuery-fetchAll(PDO::FETCH_ASSOC);

不填寫參數(shù)的話,默認(rèn)是關(guān)聯(lián)和索引都有,如下圖

php中選擇打開數(shù)據(jù)庫的方法是

在mysql數(shù)據(jù)庫中,創(chuàng)建一個(gè)test數(shù)據(jù)庫,用于測(cè)試。

請(qǐng)點(diǎn)擊輸入圖片描述

新建一個(gè)php文件,命名為test.php,用于講解php如何選擇要操作的數(shù)據(jù)庫。

請(qǐng)點(diǎn)擊輸入圖片描述

在test.php文件中,使用header()方法將頁面的編碼格式設(shè)置為utf-8,避免輸出中文亂碼。

請(qǐng)點(diǎn)擊輸入圖片描述

在test.php文件中,使用mysql_connect()函數(shù),通過賬號(hào)和密碼創(chuàng)建一個(gè)數(shù)據(jù)庫的連接。

請(qǐng)點(diǎn)擊輸入圖片描述

在test.php文件中,再使用mysql_select_db()函數(shù)選擇要操作的數(shù)據(jù)庫test,選擇數(shù)據(jù)庫成功,則返回true,否則,返回false。最后,通過if語句判斷結(jié)果。

請(qǐng)點(diǎn)擊輸入圖片描述

在瀏覽器打開test.php文件,查看結(jié)果。

請(qǐng)點(diǎn)擊輸入圖片描述

END

總結(jié):

1、創(chuàng)建一個(gè)test數(shù)據(jù)庫。

2、使用mysql_connect()函數(shù)創(chuàng)建一個(gè)數(shù)據(jù)庫的連接。

3、再使用mysql_select_db()函數(shù)選擇要操作的數(shù)據(jù)庫test,并通過if語句判斷結(jié)果。


名稱欄目:php數(shù)據(jù)庫方法嗎,php可以支持目前主流的數(shù)據(jù)庫
當(dāng)前URL:http://weahome.cn/article/hcohdc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部