程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> PHP連接MySQL的2種方法小結以及防止亂碼

PHP連接MySQL的2種方法小結以及防止亂碼

編輯:PHP綜合

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(" <br />".$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 ("<table border=1>");
                                        while($row = mysql_fetch_assoc($rs))
                                        {
                                                echo "<tr>" .
                                                "<td>$row[theindex]</td>" .
                                                "<td>$row[name]</td>" .
                                                "</tr>";
                                        }
                                        mysql_free_result($rs);
                                        }
                                        echo ("</table>");
        mysql_close($con);
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved