PHP5.4串連sqlserver

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   strong   ar   for   div   

1.下載微軟的php串連驅動:SQLSRV30.EXE(5.4對應,後面的native client要用2012)/SQLSRV20.EXE(5.3對應,native client要用2008)

2.解壓SQLSERV30.EXE,拷貝對應extension到php的ext目錄

3.配置php.ini

extension=php_sqlsrv_54_ts.dll(54為5.4版本,ts為安全執行緒,nts為非安全執行緒)

mssql.secure_connection = Off改為on 很多教程沒寫這個

4.重啟IIS/Apache

5.在sqlserver伺服器配置TCP/IP串連

6.在php伺服器下載安裝sqlserver native client

7.測試代碼

 

<?phpheader("Content-Type: text/html;charset=utf-8");class mssql{    private $host;    private $username;    private $password;    private $database;    private $handle;    private function __construct (Array $config){        $this -> host = $config[‘host‘];        $this -> username = $config[‘username‘];        $this -> password = $config[‘password‘];        $this -> database = $config[‘database‘];        $this -> init();    }    private function init() {        $dsn = ‘sqlsrv:server = ‘.$this -> host.‘;database = ‘.$this->database;        $this -> handle = new PDO($dsn,$this -> username, $this -> password);    }    public static function GetInstance(array $config = null) {        if (null == $config) {            return NULL;        }         static $db = null;        if (null == $db) {            $c = __CLASS__;            $db = new $c($config);        };        return $db -> handle;    }}$config = array(    ‘host‘ => ‘192.168.0.152,1433‘,    ‘database‘ => ‘TimeTracker‘,    ‘username‘ => ‘sa‘,    ‘password‘ => ‘123‘);$mssql = mssql::GetInstance($config);$result = $mssql->query(‘SELECT * FROM T_Sys_UserInfo‘);foreach($result as  $row){    echo $row[2];}?>

 

PHP5.4串連sqlserver

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.