怎么調(diào)用php數(shù)據(jù)庫(kù)數(shù)據(jù) php寫入數(shù)據(jù)庫(kù)

php 調(diào)用數(shù)據(jù)庫(kù)怎么調(diào)用

?php

成都網(wǎng)站建設(shè)公司更懂你!創(chuàng)新互聯(lián)只做搜索引擎喜歡的網(wǎng)站!成都網(wǎng)站制作前臺(tái)采用搜索引擎認(rèn)可的DIV+CSS架構(gòu),全站HTML靜態(tài),html5+CSS3網(wǎng)站,提供:網(wǎng)站建設(shè),微信開(kāi)發(fā),微信小程序定制開(kāi)發(fā)商城網(wǎng)站開(kāi)發(fā),成都app軟件開(kāi)發(fā)域名注冊(cè),服務(wù)器租售,網(wǎng)站代托管運(yùn)營(yíng),微信公眾號(hào)代托管運(yùn)營(yíng)。

mysql_connect("localhost","root","123456") //填寫mysql用戶名和密碼

or die("Could not connect to MySQL server!");

mysql_select_db("phpcms") //數(shù)據(jù)庫(kù)名

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

mysql_query('set names "gbk"'); //數(shù)據(jù)庫(kù)內(nèi)數(shù)據(jù)的編碼

?

js如何用php去接收數(shù)據(jù)庫(kù)中的數(shù)據(jù)

要用javascript調(diào)用php獲取數(shù)據(jù)庫(kù)接口,是一個(gè)很常見(jiàn)的前后端交互操作

通過(guò)javascript發(fā)送http請(qǐng)求php的API接口,php連接數(shù)據(jù)庫(kù)并查詢結(jié)果,最后返回出來(lái)

這樣javascript就能獲取到數(shù)據(jù)庫(kù)的數(shù)據(jù)

php調(diào)用數(shù)據(jù)庫(kù)字段

這個(gè)先連接數(shù)據(jù)庫(kù),然后調(diào)用,代碼如下:

$dbhost?=?'localhost:3306';??//?mysql服務(wù)器主機(jī)地址

$dbuser?=?'root';????????????//?mysql用戶名

$dbpass?=?'123456';??????????//?mysql用戶名密碼

$conn?=?mysqli_connect($dbhost,?$dbuser,?$dbpass);

if(!?$conn?){

die('Could?not?connect:?'?.?mysqli_error());

}

echo?'數(shù)據(jù)庫(kù)連接成功!';mysqli_close($conn);

$sql=mysql_query("select?*??from?wx_agent_orders?where?id=1");

$row=mysql_query($conn,$sql);

while($r=mysql_fetch_array($row)){

echo?$r['sendcontent']

}

這是最基礎(chǔ)的php獲取mysql方法了,希望采納

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

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

(1)integer

ora_logon(string

user

,

string

password)

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

(2)integer

ora_open(integer

connection)

打開(kāi)給出的連接的游標(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ù)解析過(guò)的查詢。

(6)boolean

ora_fetch(integer

cursor)

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

(7)string

ora_getcolumn(integer

cursor,

integer

column)

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

(8)boolean

ora_logoff(integer

connection)

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

以下是向ORACLE數(shù)據(jù)庫(kù)插入數(shù)據(jù)的示例程序:

html

headtitle向ORACLE數(shù)據(jù)庫(kù)中插入數(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)頁(yè)顯示中文

putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");

if($connection=ora_logon("scott","tiger"))

{

//庫(kù)表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

分享文章:怎么調(diào)用php數(shù)據(jù)庫(kù)數(shù)據(jù) php寫入數(shù)據(jù)庫(kù)
瀏覽地址:http://muchs.cn/article48/hheehp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、服務(wù)器托管響應(yīng)式網(wǎng)站、外貿(mào)建站、手機(jī)網(wǎng)站建設(shè)商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司