
正文
php数据库信息调用 php数据库语句
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP调用三种数据库的方法(3)
Oracle(甲骨文)是世界上最为流行的关系数据库。它是大公司推崇的工业化的强有力的引擎。我们先看看其相关的函数php数据库信息调用:
(1)integer
ora_logon(string
user
,
string
password)
开始对一个Oracle数据库服务器的连接。
(2)integer
ora_open(integer
connection)
打开给出的连接的游标。
(3)integer
ora_do(integer
connection,
string
query)
在给出的连接上执行查询。PHP生成一个指示器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数据库插入数据的示例程序php数据库信息调用:
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
相关问答
Q1: php 调用数据库怎么调用
?php
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"'); //数据库内数据的编码
?
Q2: PHP调取数据库字段信息如何限定必须某个参数大于0才允许调用
三种方式:
1通过if 判断,在循环的时候如果小于0,那么就不获取相应值。
2在赋值之前,也就是在控制器里面判断小于0的值删除掉。
3在写SQL 的时候,通过where 进行过滤筛选。
Q3: PHP用户类的一个方法怎样调用数据库操作类
直接调用就行了php数据库信息调用,不过可能php数据库信息调用你需要引用文件php数据库信息调用,以下是例子
//文件conn.php,用于连接数据库
class
DB_Conn
{
}
//文件
db.php,
用于数据库操作,这个类必然需要使用数据库连接对象,因此引用conn.php
require_once
conn.php;
class
DB
{
}
//文件user.php
require_once
'db.php';
class
User
{
public
function
getUserById($id)
{
$conn
=
new
Db_Conn();
$db
=
new
Db();
}
}以上只是示意,如果文件不在一个目录下记得修改路径。而且,一般来说数据库对象应该包含连接数据库和数据操作php数据库信息调用的全部功能,不需要分别写在两个类里面。我觉得php数据库信息调用你对面向对象的理解还很浅薄,需要进一步累积经验。
Q4: php调用数据库字段
我说一下几个步骤:
1、首先你得有一个存储这些数据的数据库表,比如数据库表的结构是这样的。
数据库表名为:user
字段:编号(id),姓名(name),手机(mobile),产品名称(productName) 主键为id
2、实现你需要的功能:
第一步:你需要连接数据库,有一个连接数据库的文件:conn.php。内容如下:
// 我假设你的数据库是mysql的,假设你的数据库用户名为root,密码为123456,根据你数据库的实际情况改写成你的。数据库名称假设为db_889888658
?php
$conn=mysql_connect("localhost","root","123456") or die("数据库连接失败,请检查用户名或密码");
mysql_select_db("db_889888658",$conn);
mysql_query("SET NAMES 'gb2312'");
?
第二步:你需要一个添加数据的表单,就相当于一个注册或添加数据的页面。如文件为:add.html内容如下:
form action="reg.php" method="post"
input type="text" name="name"br/
input type="text" name="mobile"br/
input type="text" name="productName"/br
input type="submit" name="submit" value="添加数据"
/form
第三步:写一个处理你表单提交的数据的文件reg.php。内容如下:
?php
include "conn.php";
if(isset($_POST["submit"])){
$name=$_POST["name"];
$mobile=$_POST["mobile"];
$productName=$_POST["productName"];
$sql="INSERT INTO 'user'(id,name,mobile,productName) VALUES (NULL,$name,$mobile,$productName)";
$query=mysql_query($sql);
$num=mysql_affected_rows($conn);
if($num=1){
echo "scriptalert('数据添加成功');location.href='add.html';/script";
}else{
echo "scriptalert('数据添加失败');history.back();/script";
}
}
?
第四步,第三步已经实现你说的第一个功能。下面说一下你的第二个功能。写一个表单,输入你要查询的手机号,点击“查询”按钮查询你想要的字段。
?php
if($_POST["submit"]){
$mobile=$_POST["mobile"];
if(!empty($mobile)){
include "conn.php";
$sql="SELECT * FROM 'user' WHERE 'mobile'='$mobile'";
$query=mysql_query($sql);
while($rs=mysql_fetch_array($query)){
$str="查询结果:br/";
$str.="用户名:".$rs["name"]." ";
$str.="产品名:".$rs["name"]." ";
}
echo "您查询的手机号为".$mobile."的数据信息如下:br/";
echo $str;
}else{
echo "请输入手机号";
}
}
?
form action="" method="post"
请输入您要查询的手机号:input type="text" name="mobile" input type="submit" name="submit" value="查询"
/form
关于php数据库信息调用和php数据库语句的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







