PHP讀取MySQL資料

2022-08-09 23:48:15 字數 755 閱讀 4212

先配置一下資料庫:

define("db_host","localhost");//

資料庫位址,一般為localhost

define("db_user","root");//

資料庫使用者名稱

define("db_psw","");//

資料庫密碼

define("db_db","databasename");//

需要操作的資料庫

連線:

$conn = mysql_connect(db_host,db_user,db_psw) or die('連線資料庫失敗'.mysql_error);

選擇資料庫:

mysql_select_db(db_db,$conn) or die('選擇資料庫失敗'.mysql_error);

檢索表:(自己填寫tablename)

$result = mysql_query("select * from tablename") or die('出錯了'.mysql_error);

輸出檢索的內容:

while ($row = mysql_fetch_row($result

))

echo '

';}

6最後還是要關閉的:

mysql_free_result($result

);mysql_close($conn);

PHP使用PDO從mysql讀取大量資料處理詳解

前言 環境適用場景 需要處理一定資料集業務 pdo 關鍵設定 dbh new pdo dsn,user,pass 關鍵設定,如果不設定,php依舊會從pdo一次取出資料到php dbh setattribute pdo mysql attr use buffered query,false perp...

PHP讀取Excel資料

承接上篇 設定reader和編碼 file path test.xls excel5 reader new phpexcel reader excel5 excel5 reader defaultencoding encoding excel2007 reader new phpexcel read...

php讀取mysql中文資料出現亂碼的解決方法

1.php頁面語言本身的編碼型別不合適,這時候,你直接在指令碼中寫的中文肯定是亂碼,不用說資料庫了 解決方法 選擇 utf8 或者 gb2312 這樣客戶瀏覽器會自動選擇並出現正確的中文顯示。注意 utf8 或者 gb2312 都程式設計客棧可以正確顯示中文的。2.資料庫mysql中的編碼型別不正確...