当前位置:Gxlcms > PHP教程 > php连接mysql二种方法mysql乱码问题

php连接mysql二种方法mysql乱码问题

时间:2021-07-01 10:21:17 帮助过:25人阅读

  1. //在conf/php.ini中,在vim用"/php_mysql"搜索到extension=php_mysql.dll,去掉前面的";",同时在下面增加extension=php_mysqli.dll;
  2. $mysqli = new mysqli("127.0.0.1","用户名", 密码","库名");
  3. $query="select * from 表 order by theindex desc";
  4. $mysqli->query("set names gb2312");//注意此处不加会乱码
  5. $result = $mysqli->query($query);
  6. //printf() 函数输出格式化的字符串
  7. while(list($name, $theindex) = $result->fetch_row())
  8. echo("
    ".$name.$theindex);
  9. $con = mysql_connect("localhost", "用户名", "密码");
  10. if ($con) {
  11. mysql_query("set names 'gb2312'");
  12. mysql_select_db("库名", $con);//注意此处不加会乱码
  13. $rs = mysql_query("select * from 表 order by theindex desc;", $con);
  14. if ($rs) {
  15. echo ("");
  16. while($row = mysql_fetch_assoc($rs))
  17. {
  18. echo "
  19. " .
  20. "
  21. " .
  22. "
  23. " .
  24. "
  25. ";
  26. }
  27. mysql_free_result($rs);
  28. }
  29. echo ("
  30. $row[theindex]$row[name]
    ");
  31. mysql_close($con);
  32. }

人气教程排行