PHP连接MySQL的2种方法小结以及防止乱码

PHPMysqL配置

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中,同时在下面增加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("
".$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 ("

");
while($row = MysqL_fetch_assoc($rs))
{
echo " " " " }
MysqL_free_result($rs);
}
echo (" MysqL_close($con);
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...