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...