|
php的MySQL配置
報(bào)錯(cuò)信息:Class 'mysqli' not found in
Answer:
1.在conf/php.ini中,在vim用"/php_mysql"搜索到extension=php_mysql.dll,去掉前面的";",
同時(shí)在下面增加extension=php_mysqli.dll;
注意后面那個(gè)dll多了個(gè)i
2."/extension_dir"檢查路徑是否正確;
3.找到ext/目錄,把其中的php_mysql.dll,php_mysqli.dll兩個(gè)文件Copy to %systemroot%/system32下.
4.重啟服務(wù)
連接數(shù)據(jù)庫
復(fù)制代碼 代碼如下:
//在conf/php.ini中,在vim用"/php_mysql"搜索到extension=php_mysql.dll,去掉前面的";",同時(shí)在下面增加extension=php_mysqli.dll;
$mysqli = new mysqli("127.0.0.1","用戶名", 密碼","庫名");
$query="select * from 表 order by theindex desc";
$mysqli->query("SET NAMES gb2312");//注意此處不加會亂碼
$result = $mysqli->query($query);
//printf() 函數(shù)輸出格式化的字符串
while(list($name, $theindex) = $result->fetch_row())
echo(" <br />".$name.$theindex);
$con = mysql_connect("localhost", "用戶名", "密碼");
if ($con) {
mysql_query("set names 'gb2312'");
mysql_select_db("庫名", $con);//注意此處不加會亂碼
$rs = mysql_query("select * from 表 order by theindex desc;", $con);
if ($rs) {
echo ("<table border=1>");
while($row = mysql_fetch_assoc($rs))
{
echo "<tr>" .
"<td>$row[theindex]</td>" .
"<td>$row[name]</td>" .
"</tr>";
}
mysql_free_result($rs);
}
echo ("</table>");
mysql_close($con);
}
php技術(shù):PHP連接MySQL的2種方法小結(jié)以及防止亂碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。