当前位置: 编程技术>php
php连接mysql二种方法 mysql乱码问题
来源: 互联网 发布时间:2014-08-30
本文导语: php与mysql配置报错信息:class 'mysqli' not found in 解决方法: 1,在conf/php.ini中,在vim用"/php_mysql"搜索到extension=php_mysql.dll,去掉前面的";", 同时在下面增加extension=php_mysqli.dll; 注意后面那个dll多了个i 2,"/extension_dir"检查路径是否正确...
php与mysql配置报错信息:class 'mysqli' not found in
解决方法:
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,重启mysql数据库服务
连接数据库
代码示例:
//在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 "" .
"$row[theindex]" .
"$row[name]" .
"";
}
mysql_free_result($rs);
}
echo ("");
mysql_close($con);
}
$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 "" .
"$row[theindex]" .
"$row[name]" .
"";
}
mysql_free_result($rs);
}
echo ("");
mysql_close($con);
}