PHP PDO MySQL 長連結設定及影響
設定短連接,一次資料庫查詢程式
1 2 3 4 5 6 7 8 |
$PDO = new PDO( PDO_DSN, MYSQL_USERNAME, MYSQL_PASSWORD, array( PDO::ATTR_PERSISTENT => false ) ); $PDO->exec("set names utf8"); $sql = " SELECT * FROM UserLog "; $pre = $PDO->prepare($sql); $pre->execute(); |
短連接,一次資料庫查詢結果
1 2 3 4 5 |
"2016-04-26 09:34:55","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",86,0,"Connect","MJAPP_SoundU@localhost on MJAPP_SoundU2" "2016-04-26 09:34:55","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",86,0,"Query","set names utf8" "2016-04-26 09:34:55","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",86,0,"Query","SET GLOBAL time_zone='+8:00'" "2016-04-26 09:34:55","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",86,0,"Query","SELECT * FROM UserLog" "2016-04-26 09:34:56","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",86,0,"Quit","" |
設定為長連接 PDO::ATTR_PERSISTENT => true
1 2 3 4 5 6 7 8 |
$PDO = new PDO( PDO_DSN, MYSQL_USERNAME, MYSQL_PASSWORD, array( PDO::ATTR_PERSISTENT => true ) ); $PDO->exec("set names utf8"); $sql = " SELECT * FROM UserLog "; $pre = $PDO->prepare($sql); $pre->execute(); |
長連接,一次資料庫查詢結果
1 2 3 |
"2016-04-26 09:38:38","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",87,0,"Connect","MJAPP_SoundU@localhost on MJAPP_SoundU2" "2016-04-26 09:38:38","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",87,0,"Query","set names utf8" "2016-04-26 09:38:38","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",87,0,"Query","SELECT * FROM UserLog" |
短連接,連續多查詢程式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$PDO = new PDO( PDO_DSN, MYSQL_USERNAME, MYSQL_PASSWORD, array( PDO::ATTR_PERSISTENT => false ) ); $PDO->exec("set names utf8"); $sql = " SELECT * FROM UserLog LIMIT 1 "; $pre = $PDO->prepare($sql); $pre->execute(); $sql = " SELECT * FROM UserLog LIMIT 1 "; $pre = $PDO->prepare($sql); $pre->execute(); $sql = " SELECT * FROM UserLog LIMIT 1 "; $pre = $PDO->prepare($sql); $pre->execute(); |
短連接,連續多查詢結果
1 2 3 4 5 6 |
"2016-04-26 10:57:16","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",123,0,"Connect","MJAPP_SoundU@localhost on MJAPP_SoundU2" "2016-04-26 10:57:16","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",123,0,"Query","set names utf8" "2016-04-26 10:57:16","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",123,0,"Query","SELECT * FROM UserLog LIMIT 1" "2016-04-26 10:57:16","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",123,0,"Query","SELECT * FROM UserLog LIMIT 1" "2016-04-26 10:57:16","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",123,0,"Query","SELECT * FROM UserLog LIMIT 1" "2016-04-26 10:57:16","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",123,0,"Quit","" |
長連接,連續多查詢程式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$PDO = new PDO( PDO_DSN, MYSQL_USERNAME, MYSQL_PASSWORD, array( PDO::ATTR_PERSISTENT => true ) ); $PDO->exec("set names utf8"); $sql = " SELECT * FROM UserLog LIMIT 1 "; $pre = $PDO->prepare($sql); $pre->execute(); $sql = " SELECT * FROM UserLog LIMIT 1 "; $pre = $PDO->prepare($sql); $pre->execute(); $sql = " SELECT * FROM UserLog LIMIT 1 "; $pre = $PDO->prepare($sql); $pre->execute(); |
長連接,連續多查詢結果
1 2 3 4 |
"2016-04-26 10:58:28","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",66,0,"Query","set names utf8" "2016-04-26 10:58:28","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",66,0,"Query","SELECT * FROM UserLog LIMIT 1" "2016-04-26 10:58:28","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",66,0,"Query","SELECT * FROM UserLog LIMIT 1" "2016-04-26 10:58:28","MJAPP_SoundU[MJAPP_SoundU] @ localhost []",66,0,"Query","SELECT * FROM UserLog LIMIT 1" |
--
6,914 total views, 2 views today
先生您好:
拜讀您寫的好文章
PDO 長連接 PDO::ATTR_PERSISTENT 測試及了解
請問 查詢結果 是用什麼軟體/程式 取得的? 煩請告知好嗎?
劉鎮城上