调php用数据库的方法 php 数据库操作

php 调用数据库怎么调用

?php

创新互联公司主营南安网站建设的网络公司,主营网站建设方案,手机APP定制开发,南安h5小程序设计搭建,南安网站营销推广欢迎南安等地区企业咨询

mysql_connect("localhost","root","123456") //填写mysql用户名和密码

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

mysql_select_db("phpcms") //数据库名

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

mysql_query('set names "gbk"'); //数据库内数据的编码

?

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

headtitle向ORACLE数据库中插入数据/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

?

//先设置两个环境变量ORACLE_HOME,ORACLE_SID

putenv("ORACLE_HOME=/oracle/app/oracle/product/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

php中选择打开数据库的方法是

在mysql数据库中,创建一个test数据库,用于测试。

请点击输入图片描述

新建一个php文件,命名为test.php,用于讲解php如何选择要操作的数据库。

请点击输入图片描述

在test.php文件中,使用header()方法将页面的编码格式设置为utf-8,避免输出中文乱码。

请点击输入图片描述

在test.php文件中,使用mysql_connect()函数,通过账号和密码创建一个数据库的连接。

请点击输入图片描述

在test.php文件中,再使用mysql_select_db()函数选择要操作的数据库test,选择数据库成功,则返回true,否则,返回false。最后,通过if语句判断结果。

请点击输入图片描述

在浏览器打开test.php文件,查看结果。

请点击输入图片描述

END

总结:

1、创建一个test数据库。

2、使用mysql_connect()函数创建一个数据库的连接。

3、再使用mysql_select_db()函数选择要操作的数据库test,并通过if语句判断结果。

网站名称:调php用数据库的方法 php 数据库操作
URL分享:https://www.cdcxhl.com/article30/dodhhpo.html

成都网站建设公司_创新互联,为您提供面包屑导航网站收录服务器托管ChatGPT企业建站云服务器

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

营销型网站建设