Home php教程 php手册 PHP连接数据库的方法(2)

PHP连接数据库的方法(2)

Jun 21, 2016 am 09:02 AM
gt integer lt odbc string

 

if($field_value==""){

echo "

";

}

else{

echo "$field_value ";

}

}

echo "tr>";

}

echo "";//表格输出结束

mysql_free_result($rst) or die("
无法释放result资源!");//释放result资源

}

else{

echo "
目前该表中没有任何数据!";

}

mysql_close($server) or die("
无法与服务器断开连接!");//断开连接并释放资源

?>

开放数据库连接(ODBC)已成为一种与数据库进行通信的工业标准。PHP也提供了标准的接口,使得PHP能调用AccessSQL SERVER等数据库。其相关函数是:

1integer odbc_connect(string dsn, string user, string password)

连接到一个ODBC数据库源名字上。

2integer odbc_exec(integer connection, string query) odbc_do(integer connection, string query)

在一个连接上执行查询。

3boolean odbc_fetch_row(integer result, integer row)

从一个结果集中获取一行数据。Row参数是可选的,若为空缺,则返回下一个有效行。在结果集中不再剩余行时返回false

4boolean odbc_close(integer connection)

关闭一个数据库的连接。若在该连接上有打开的事务,则返回一个错误,而且连接不会被关闭。

最后,还是看个分页的例子:



//
设定每页显示条数

$show_num = 10;

$spages = $pages;//
避免$pages后期被改变

//
定义连接

$dsn = "localhost";

$user = "sa";

$password = "";

//
计算总记录数

$rs_num = "select count(*) as id from bbs where zu='0' and lei='".$lei."'";

$conn_id = odbc_connect($dsn,$user,$password);

$rnum = odbc_exec($conn_id,$rs_num);

while(odbc_fetch_row($rnum)){

$total_rs = odbc_result($rnum,"id");//
将总记录数放入$total_rs变量

}

//
计算与页有关的条数

$nnn = $total_rs / $show_num;//
计算总页数

$hnnn = intval($nnn);//
将总页数取整

$cnnnn = $nnn - $hnnn;

//
计算所需总页数

switch ($cnnn){

case "0":

$hnnn++;

$nnn = $hnnn;//
总页数

break;

default :

$nnn = $hnnn;//
总页数

break;

};

if ($nnn == 0)$nnn++;

//
计算页面改变所需的条件

$fore = $pages;

$next = $pages;

$fore -= 1;

$next += 1;

if ($fore > 0) {

echo "
首页";

echo "
前页";

};

if ($pages nnn
) {

echo "后页";

echo "尾页";

};

echo "".$nnn."";

$query_string = "SELECT * FROM table where condition order by you wanted order";

$cur = odbc_exec($conn_id,$query_string);

//
取到循环的顶部

$cnum = ($pages-1) * $show_num;//
计算当前的记录游标的位置

//
空循环到显示记录游标处

if ($cnum != 0){

for ($i=0;$icnum;odbc_fetch_row
($cur)){$i++;};

};

$i=1;

//显示记录

while(odbc_fetch_row($cur)){

echo ;

if ($i == $show_num){//
在不满页数时跳出程序

break;

};

$i++;

};

//
关闭连接

odbc_close($conn_id);

?>

Oracle
(甲骨文)是世界上最为流行的关系数据库。它是大公司推崇的工业化的强有力的引擎。我们先看看其相关的函数:

1integer ora_logon(string user , string password)

开始对一个Oracle数据库服务器的连接。

2integer ora_open(integer connection)

打开给出的连接的游标。

3integer ora_do(integer connection, string query)

在给出的连接上执行查询。PHP生成一个指示器,解析查询,并执行之。

4integer ora_parse(integer cursor, string query)

解析一个查询并准备好执行。

5boolean ora_exec(integer cursor)

执行一个先前由ora_parse函数解析过的查询。

6boolean ora_fetch(integer cursor)

此函数会使得一个执行过的查询中的行被取到指示器中。这使得您可以调用ora_getcolumn函数。

7string ora_getcolumn(integer cursor, integer column)

返回当前的值。列由零开始的数字索引。

8boolean ora_logoff(integer connection)

断开对数据库服务器的链接。

以下是向ORACLE数据库插入数据的示例程序:



ORACLE数据库中插入数据





cellspacing="0" cellpadding="0">

tr>

th>IDth>

th>nameth>

th>Descriptionth>

tr>

tr>







tr>

tr align="center">



tr>

maxlength="50" size="10"> maxlength="255" size="30"> maxlength="255" size="50"> colspan="3">提交">  ;重写">






//
先设置两个环境变量ORACLE_HOMEORACLE_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")) {

//
库表testID,name,Description三项

$sql = 'insert into test(ID,name,Description) values ';

$sql .= '('' . $ID . '','' . $name . '',''. $Description . '')';

if($cursor=ora_do($connect,$sql)) {



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Convert basic data types to strings using Java's String.valueOf() function Convert basic data types to strings using Java's String.valueOf() function Jul 24, 2023 pm 07:55 PM

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

How to convert char array to string How to convert char array to string Jun 09, 2023 am 10:04 AM

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Use Java's String.replace() function to replace characters (strings) in a string Use Java's String.replace() function to replace characters (strings) in a string Jul 25, 2023 pm 05:16 PM

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

2w words detailed explanation String, yyds 2w words detailed explanation String, yyds Aug 24, 2023 pm 03:56 PM

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.

Use java's String.length() function to get the length of a string Use java's String.length() function to get the length of a string Jul 25, 2023 am 09:09 AM

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

How to use java's String class How to use java's String class Apr 19, 2023 pm 01:19 PM

1. Understanding String1. String in JDK First, let’s take a look at the source code of the String class in the JDK. It implements many interfaces. You can see that the String class is modified by final. This means that the String class cannot be inherited and there is no subclass of String. class, so that all people using JDK use the same String class. If String is allowed to be inherited, everyone can extend String. Everyone uses different versions of String, and two different people Using the same method shows different results, which makes it impossible to develop the code. Inheritance and method overriding not only bring flexibility, but also cause many subclasses to behave differently.

See all articles