PHP的MySQL配置
報錯信息:Class 'mysqli' not found in
Answer:
1.在conf/php.ini中,在vim用"/php_mysql"搜索到extension=php_mysql.dll,去掉前面的";",
同時在下面增加extension=php_mysqli.dll;
注意後面那個dll多了個i
2."/extension_dir"檢查路徑是否正確;
3.找到ext/目錄,把其中的php_mysql.dll,php_mysqli.dll兩個文件Copy to %systemroot%/system32下.
4.重啟服務
連接數據庫
復制代碼 代碼如下:
//在conf/php.ini中,在vim用"/php_mysql"搜索到extension=php_mysql.dll,去掉前面的";",同時在下面增加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() 函數輸出格式化的字符串
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);
}