PHP串連MySQL的2種方法以及防止亂碼_PHP教程

來源:互聯網
上載者:User
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);
}

http://www.bkjia.com/PHPjc/730939.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/730939.htmlTechArticlePHP的MySQL配置 報錯資訊:Class 'mysqli' not found in Answer: 1.在conf/php.ini中,在vim用/php_mysql搜尋到extension=php_mysql.dll,去掉前面的;, 同時在下面增加...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.