调用数据库php代码,调用数据库php代码命令

php连接数据库代码

?php

创新互联公司主要从事成都网站建设、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务新蔡,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

$host="localhost";

$db_user="root"; //数据库用户名

$db_pass="root"; //数据库密码

$db_name="dzjgj";//数据库名

$timezone="Asia/Shanghai";

$link=mysql_connect($host,$db_user,$db_pass);

mysql_select_db($db_name,$link);

mysql_query("SET names UTF8");

header("Content-Type: text/html; charset=utf-8");

date_default_timezone_set($timezone); //北京时间

?

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

html通过php调用数据库

在html中调用php内容,可以用script src="friendlinks.php"/script然后在friendlinks.php中调取数据库数据。并输出适当的html,或者输出xml、json都可以,只是图简单的话,只要输出html就行了。

如何用php调用mysql中的数据

大概的基本流程如下:

连接数据库,再加一个判断。

选择数据库

读取表

输出表中数据

下面是代码:

?php

$con

= mysql_connect("localhost","root","abc123");

/*

localhost

是服务器

root

是用户名 abc123

是密码*/ 

if

(!$con)

{

die("数据库服务器连接失败");

}

/* 这就是一个逻辑非判断,如果错误就输出括号里的字符串

*/ 

@mysql_select_db("a", $con); 

/* 选择mysql服务器里的一个数据库,假设你的数据库名为 a*/ 

$sql = "SELECT * FROM

qq"; 

/*

定义变量sql, "SELECT * FROM qq"

是SQL指令,表示选取表qq中的数据 */ 

$result

= mysql_query($sql);

//执行SQL语句,获得结果集 

/*下面就是选择性的输出打印了,由于不清楚你的具体情况给你个表格打印吧*/

//打印表格 

echo

"table

border=1"; 

while(

$row

=

mysql_fetch_array($result)

)

/*逐行获取结果集中的记录,得到数组row */

{

/*数组row的下标对应着数据库中的字段值 */

$id

=

$row['id']; 

$name

=

$row['name']; 

$sex

=

$row['sex']; 

echo

"tr"; 

echo

"td$id/td"; 

echo

"td$name/td"; 

echo

"td$sex/td"; 

echo

"/tr"; 

echo

"table

/"; 

?

如果你的switch是表头,就定义这个表头字段,然后输出。

你可以去后盾人平台看看,里面的东西不错

Ajax怎么调用后台php代码访问数据库并显示

由 JavaScript 调用的服务器页面,是名为 "getuser.php" 的简单 PHP 文件。

该页面用 PHP 编写,并使用 MySQL 数据库。

其中的代码执行针对数据库的 SQL 查询,并以 HTML 表格返回结果:

?php

$q=$_GET["q"];

$con = mysql_connect('localhost', 'peter', 'abc123');

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "table border='1'

tr

thFirstname/th

thLastname/th

thAge/th

thHometown/th

thJob/th

/tr";

while($row = mysql_fetch_array($result))

{

echo "tr";

echo "td" . $row['FirstName'] . "/td";

echo "td" . $row['LastName'] . "/td";

echo "td" . $row['Age'] . "/td";

echo "td" . $row['Hometown'] . "/td";

echo "td" . $row['Job'] . "/td";

echo "/tr";

}

echo "/table";

mysql_close($con);

?

例子解释:

当查询从 JavaScript 被发送到这个 PHP 页面,会发生:

PHP 打开到达 MySQL 服务器的连接

找到拥有指定姓名的 "user"

创建表格,插入数据,然后将其发送到 "txtHint" 占位符

网站标题:调用数据库php代码,调用数据库php代码命令
文章位置:https://www.cdcxhl.com/article6/hsjiig.html

成都网站建设公司_创新互联,为您提供定制网站网站内链服务器托管网站策划面包屑导航网站设计

广告

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

网站建设网站维护公司