Open Database Connectivity (ODBC) has become an industry standard for communicating with databases. PHP also provides a standard interface that allows PHP to invoke databases such as Access,sql server. Its 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)
Executes the query on a connection.
(3) Boolean odbc_fetch_row (integer result, integer row)
Gets a row of data from a result set. The row parameter is optional, and if it is empty, the next valid row is returned. Returns False when no more rows are left in the result set.
(4) Boolean odbc_close (integer connection)
Closes a connection to a database. If there is an open transaction on the connection, an error is returned and the connection is not closed.
Finally, here's an example of paging:
Set the number of bars per page
$show _num = 10;
$spages = $pages;//Avoid $pages later change
Defining connections
$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 the $TOTAL_RS variable
}
Calculate the number of bars related to a page
$nnn = Total pages Calculated $total _rs/$show _num;//
$hnnn = Intval ($nnn);//Rounding Total pages
$cnnnn = $nnn-$hnnn;
Calculate the total number of pages required
Switch ($cnnn) {
Case "0":
$HNNN + +;
$nnn = $hnnn;//Total pages
Break
Default:
$nnn = $hnnn;//Total pages
Break
};
if ($nnn = = 0) $nnn + +;
The conditions required to calculate the page change
$fore = $pages;
$next = $pages;
$fore-= 1;
$next + = 1;
if ($fore > 0) {
echo "Home";
echo "front page";
};
if ($pages < $nnn) {
echo "Back Page";
echo "Last";
};
echo "Total". $nnn. " Page ";
$query _string = "SELECT * FROM table where condition order by you wanted order";
$cur = Odbc_exec ($conn _id, $query _string);
Take to the top of the loop
$cnum = ($pages-1) * $show _num;//calculates the position of the current record cursor
Empty loop to show record cursor at
if ($cnum! = 0) {
for ($i =0; $i <= $cnum; Odbc_fetch_row ($cur)) {$i + +;};
};
$i = 1;
Show Records
while (Odbc_fetch_row ($cur)) {
echo;
if ($i = = $show _num) {//Jump out of the program on pages
Break
};
$i + +;
};
Close connection
Odbc_close ($conn _id);
?>
http://www.bkjia.com/PHPjc/315535.html www.bkjia.com true http://www.bkjia.com/PHPjc/315535.html techarticle Open Database Connectivity (ODBC) has become an industry standard for communicating with databases. PHP also provides a standard interface that allows PHP to invoke databases such as Access,sql server. The relevant letter ...