首页 > 后端开发 > php教程 > PHP连接MySQL的2种方法小结以及防止乱码_PHP教程

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

WBOY
发布: 2016-07-13 10:36:15
原创
994 人浏览过

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("
".$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 ("
$row[theindex]$row[name]
");
        mysql_close($con);
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/740211.htmlTechArticlePHP的MySQL配置 报错信息:Class 'mysqli' not found in Answer: 1.在conf/php.ini中,在vim用"/php_mysql"搜索到extension=php_mysql.dll,去掉前面的";", 同时在下面增...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板