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