Home >Backend Development >PHP Tutorial >Two ways to connect php to mysql. Mysql garbled problem

Two ways to connect php to mysql. Mysql garbled problem

WBOY
WBOYOriginal
2016-07-25 08:53:57900browse
  1. //In conf/php.ini, use "/php_mysql" in vim to search extension=php_mysql.dll, remove the ";" in front, and add extension=php_mysqli.dll;
  2. $mysqli below = new mysqli("127.0.0.1","Username", Password","Library name");
  3. $query="select * from table order by theindex desc";
  4. $mysqli->query("set names gb2312");//Be careful not to add garbled characters here
  5. $result = $mysqli->query($query);
  6. //printf() function outputs a formatted string
  7. while(list($name, $ theindex) = $result->fetch_row())
  8. echo("
    ".$name.$theindex);
  9. $con = mysql_connect("localhost", "username", "password") ;
  10. if ($con) {
  11. mysql_query("set names 'gb2312'");
  12. mysql_select_db("library name", $con);//Be careful not to add garbled characters here
  13. $rs = mysql_query("select * from table 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. }
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn