PHP連接MySQL的2種方法小結(jié)以及防止亂碼
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ù)庫
//在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");//注意此處不加會(huì)亂碼
$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);//注意此處不加會(huì)亂碼
$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);
}
相關(guān)文章
php curl批處理實(shí)現(xiàn)可控并發(fā)異步操作示例
這篇文章主要介紹了php curl批處理實(shí)現(xiàn)可控并發(fā)異步操作,結(jié)合實(shí)例形式分析了php使用curl的curl_multi_*族函數(shù)進(jìn)行并發(fā)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-05-05PHP實(shí)現(xiàn)防止表單重復(fù)提交功能【基于token驗(yàn)證】
這篇文章主要介紹了PHP實(shí)現(xiàn)防止表單重復(fù)提交功能,結(jié)合實(shí)例形式分析了php基于token驗(yàn)證防止表單重復(fù)提交的相關(guān)操作技巧,非常簡單實(shí)用,需要的朋友可以參考下2018-05-05學(xué)習(xí)php設(shè)計(jì)模式 php實(shí)現(xiàn)享元模式(flyweight)
這篇文章主要介紹了php設(shè)計(jì)模式中的享元模式,使用php實(shí)現(xiàn)享元模式,感興趣的小伙伴們可以參考一下2015-12-12