Home Backend Development PHP Tutorial How to call three databases with PHP (2)_PHP tutorial

How to call three databases with PHP (2)_PHP tutorial

Jul 21, 2016 pm 04:05 PM
odbc p php and open become database method of transfer conduct connect communication

Open Database Connectivity (ODBC) has become an industry standard for communicating with databases. PHP also provides a standard interface, allowing PHP to call Access, SQL SERVER and other databases. The related functions are:

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

Connect to an ODBC database source name.

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

Execute a query on a connection.

(3) boolean odbc_fetch_row(integer result, integer row)

Get a row of data from a result set. The Row parameter is optional. If left blank, the next valid row is returned. Returns false when there are no more rows remaining in the result set.

(4) boolean odbc_close(integer connection)

Close a database connection. If there is an open transaction on the connection, an error is returned and the connection is not closed.

Finally, let’s look at an example of paging:

<?

//Set the number of items displayed on each page

$show_num = 10;

$spages = $pages;//Avoid $pages being changed later

//Define the connection

$dsn = "localhost";

$ user = "sa";

$password = "";

//Calculate the total number of records

$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");//Put the total number of records into $ total_rs variable

}

//Calculate the number of items related to the page

$nnn = $total_rs / $show_num;//Calculate the total number of pages

$hnnn = intval($nnn);//Round the total number of pages

$cnnnn = $nnn - $hnnn;

//Calculate the total number of pages required

switch ($cnnn){

case "0":

$hnnn++;

$nnn = $hnnn;//Total number of pages

break;

default:

$nnn = $hnnn;//Total number of pages

break;

};

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

//Calculate the conditions required for page changes

$fore = $pages;

$next = $pages ;

$fore -= 1;

$next += 1;

if ($fore > 0) {

echo "< a>Homepage</a>";

echo "<a>Previous page</a>";

};

if ($pages &lt ; $nnn) {

echo "<a>Next page</a>";

echo "<a>Last page</a>";

};

echo "total".$nnn."pages";

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

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

//Get to the top of the loop

$cnum = ($pages-1) * $show_num;//Calculate the current The position of the record cursor

//Empty loop to display the record cursor

if ($cnum != 0){

for ($i=0;$i&lt ;=$cnum;odbc_fetch_row($cur)){$i++;};

};

$i=1;

//Display record

while(odbc_fetch_row($cur)){

echo ;

if ($i == $show_num){//Jump out of the program when the number of pages is not satisfied

break;

};

$i++;

};

//Close the connection

odbc_close($conn_id);

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315535.htmlTechArticleOpen Database Connectivity (ODBC) has become an industry standard for communicating with databases. PHP also provides a standard interface, allowing PHP to call Access, SQL SERVER and other databases. The relevant letter...
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 Article Tags

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles