Php + mysql get records in the database (especially the efficient paging function) _ PHP Tutorial

Source: Internet
Author: User
Php + mysql obtains records in the database (especially the efficient paging function ). MySQL (the best combination with PHP). php (as the current mainstream development language) to obtain records in the database, complete personal experience, for reference only !? Php (as the mainstream development MySQL (the best combination with PHP). php (as the mainstream development language) to obtain records in the database, a complete summary of personal experience, for your reference only!
/**
* Php (as the mainstream development language) + MySQL (the best combination with PHP) basic database functions
* Http://blog.csdn.net/yown
*/
######################################## ####
# Obtain the sequence ID
######################################## ####
Function getSequence (){
$ SQL = "update sequence set id = last_insert_id (id + 1 );";
$ Sql2 = "select last_insert_id ();";

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

$ Link = MySQL (the best combination with PHP) _ connect ($ host, $ dbuser, $ dbpass );
If (! $ Link ){
Return MySQL (the best combination with PHP) _ error ();
}

MySQL (the best combination with PHP) _ select_db ($ database );
MySQL (the best combination with PHP) _ query ("set names UTF8 ");
If ($ printsql) echo"

". $ SQL ." ";
MySQL (the best combination with PHP) _ query ($ SQL );
If ($ printsql) echo" ". $ Sql2 ." ";
$ Result = MySQL (the best combination with PHP) _ query ($ sql2 );

If (MySQL (the best combination with PHP) _ num_rows ($ result) = 0 ){
MySQL (the best combination with PHP) _ close ($ link );
Return "";
}
$ Myrow = MySQL (the best combination with PHP) _ fetch_row ($ result );
$ Ret = $ myrow [0];

MySQL (the best combination with PHP) _ close ($ link );
Return $ ret;
}
######################################## ####
# Obtain the data in column N of the Nth record of strSql. the subscript starts from 1.
######################################## ####
Function getData ($ strsql, $ row, $ col ){
Global $ dbuser, $ dbpass, $ host, $ database, $ printsql;

$ Link = MySQL (the best combination with PHP) _ connect ($ host, $ dbuser, $ dbpass );
If (! $ Link ){
Return MySQL (the best combination with PHP) _ error ();
}

MySQL (the best combination with PHP) _ select_db ($ database );
MySQL (the best combination with PHP) _ query ("set names UTF8 ");
If ($ printsql) echo"

". $ Strsql ." ";
$ Result = MySQL (the best combination with PHP) _ query ($ strsql );

If (MySQL (the best combination with PHP) _ num_rows ($ result) = 0 ){
MySQL (the best combination with PHP) _ close ($ link );
Return "";
}
$ I = 0;
While ($ myrow = MySQL (the best combination with PHP) _ fetch_row ($ result )){

If ($ I = $ row-1 ){
$ Ret = $ myrow [$ col-1];
Break;
}
$ I = $ I + 1;
}

MySQL (the best combination with PHP) _ close ($ link );
Return $ ret;

}

######################################## ####
# Obtain the Nth record of strSql
######################################## ####
Function getRowData ($ strsql, $ row ){
Global $ dbuser, $ dbpass, $ host, $ database, $ printsql;

$ Link = MySQL (the best combination with PHP) _ connect ($ host, $ dbuser, $ dbpass );
If (! $ Link ){
Return MySQL (the best combination with PHP) _ error ();
}

MySQL (the best combination with PHP) _ select_db ($ database );
MySQL (the best combination with PHP) _ query ("set names UTF8 ");
If ($ printsql) echo"

". $ Strsql ." ";
$ Result = MySQL (the best combination with PHP) _ query ($ strsql );

If (MySQL (the best combination with PHP) _ num_rows ($ result) = 0 ){
MySQL (the best combination with PHP) _ close ($ link );
Return "";
}
$ I = 0;
While ($ myrow = MySQL (the best combination with PHP) _ fetch_array ($ result )){

If ($ I = $ row-1 ){
$ Ret = $ myrow;
Break;
}
$ I = $ I + 1;
}

MySQL (the best combination with PHP) _ close ($ link );
Return $ ret;

}

######################################## ####
# Getting strSql record set and saving it to the array
######################################## ####
Function getResultSetData ($ strsql ){
Global $ dbuser, $ dbpass, $ host, $ database, $ printsql;

$ Link = MySQL (the best combination with PHP) _ connect ($ host, $ dbuser, $ dbpass );
If (! $ Link ){
Return MySQL (the best combination with PHP) _ error ();
}

MySQL (the best combination with PHP) _ select_db ($ database );
MySQL (the best combination with PHP) _ query ("set names UTF8 ");
If ($ printsql) echo"

". $ Strsql ." ";
$ Result = MySQL (the best combination with PHP) _ query ($ strsql );

If (MySQL (the best combination with PHP) _ num_rows ($ result) = 0 ){
MySQL (the best combination with PHP) _ close ($ link );
Return "";
}

While ($ myrow = MySQL (the best combination with PHP) _ fetch_array ($ result )){
$ Ret [] = $ myrow;
}

MySQL (the best combination with PHP) _ close ($ link );
Return $ ret;
}

Http://www.bkjia.com/PHPjc/508634.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508634.htmlTechArticleMySQL (the best combination with PHP). php (as the current mainstream development language) to obtain records in the database, complete personal experience, for reference only! ? Php (as the mainstream development...

Related Article

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.