Php+mysql getting records in a database (especially efficient paging) _php tutorial

Source: Internet
Author: User
MySQL (the best combination with PHP). PHP (as the current mainstream development language) to get the records in the database, complete personal experience Summary, for reference only!
/**
*php (as the current mainstream development language) +mysql (and PHP collocation of the best combination) database basic functions
*http://blog.csdn.net/yown
*/
############################################
#获取序列ID
############################################
function Getsequence () {
$sql = "Update sequence set id=last_insert_id (id+1);";
$sql 2= "Select last_insert_id ();";

Global $dbuser, $dbpass, $host, $database, $printsql;

$link = MySQL (best combination with PHP) _connect ($host, $dbuser, $dbpass);
if (! $link) {
Return MySQL (the best combination of PHP collocation) _error ();
}

MySQL (the best combination of PHP collocation) _select_db ($database);
MySQL (and PHP collocation of the best combination) _query ("SET NAMES UTF8");
if ($printsql) echo "

". $sql." ";
MySQL (the best combination of PHP collocation) _query ($sql);
if ($printsql) echo " ". $sql 2." ";
$result = MySQL (the best combination of PHP collocation) _query ($sql 2);

if (the best combination of MySQL (and PHP collocation) _num_rows ($result) ==0) {
MySQL (the best combination of PHP collocation) _close ($link);
Return "";
}
$myrow = MySQL (the best combination of PHP collocation) _fetch_row ($result);
$ret = $myrow [0];

MySQL (the best combination of PHP collocation) _close ($link);
return $ret;
}
############################################
#获取strSql第N条记录中的第N列数据, subscript starting from 1
############################################
function GetData ($strsql, $row, $col) {
Global $dbuser, $dbpass, $host, $database, $printsql;

$link = MySQL (best combination with PHP) _connect ($host, $dbuser, $dbpass);
if (! $link) {
Return MySQL (the best combination of PHP collocation) _error ();
}

MySQL (the best combination of PHP collocation) _select_db ($database);
MySQL (and PHP collocation of the best combination) _query ("SET NAMES UTF8");
if ($printsql) echo "

". $strsql." ";
$result = MySQL (the best combination of PHP collocation) _query ($strsql);

if (the best combination of MySQL (and PHP collocation) _num_rows ($result) ==0) {
MySQL (the best combination of PHP collocation) _close ($link);
Return "";
}
$i = 0;
while ($myrow = MySQL (best combination with PHP) _fetch_row ($result)) {

if ($i = = $row-1) {
$ret = $myrow [$col-1];
Break
}
$i = $i +1;
}

MySQL (the best combination of PHP collocation) _close ($link);
return $ret;

}

############################################
#获取strSql第N条记录
############################################
function GetRowData ($strsql, $row) {
Global $dbuser, $dbpass, $host, $database, $printsql;

$link = MySQL (best combination with PHP) _connect ($host, $dbuser, $dbpass);
if (! $link) {
Return MySQL (the best combination of PHP collocation) _error ();
}

MySQL (the best combination of PHP collocation) _select_db ($database);
MySQL (and PHP collocation of the best combination) _query ("SET NAMES UTF8");
if ($printsql) echo "

". $strsql." ";
$result = MySQL (the best combination of PHP collocation) _query ($strsql);

if (the best combination of MySQL (and PHP collocation) _num_rows ($result) ==0) {
MySQL (the best combination of PHP collocation) _close ($link);
Return "";
}
$i = 0;
while ($myrow = MySQL (best combination with PHP) _fetch_array ($result)) {

if ($i = = $row-1) {
$ret = $myrow;
Break
}
$i = $i +1;
}

MySQL (the best combination of PHP collocation) _close ($link);
return $ret;

}

############################################
#获取strSql记录集存入数组中
############################################
function Getresultsetdata ($strsql) {
Global $dbuser, $dbpass, $host, $database, $printsql;

$link = MySQL (best combination with PHP) _connect ($host, $dbuser, $dbpass);
if (! $link) {
Return MySQL (the best combination of PHP collocation) _error ();
}

MySQL (the best combination of PHP collocation) _select_db ($database);
MySQL (and PHP collocation of the best combination) _query ("SET NAMES UTF8");
if ($printsql) echo "

". $strsql." ";
$result = MySQL (the best combination of PHP collocation) _query ($strsql);

if (the best combination of MySQL (and PHP collocation) _num_rows ($result) ==0) {
MySQL (the best combination of PHP collocation) _close ($link);
Return "";
}

while ($myrow = MySQL (best combination with PHP) _fetch_array ($result)) {
$ret []= $myrow;
}

MySQL (the best combination of PHP collocation) _close ($link);
return $ret;
}

http://www.bkjia.com/PHPjc/508634.html www.bkjia.com true http://www.bkjia.com/PHPjc/508634.html techarticle MySQL (the best combination with PHP). PHP (as the current mainstream development language) to get the records in the database, complete personal experience, for reference only!? PHP (as the mainstream development now ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.