Can PHP work with a MS SQL database

后端 未结 8 1823
轮回少年
轮回少年 2020-12-12 15:40

I work primarly with PHP & MySQL, but I have a potential client with a MS SQL and ASP setup. Due to some complicated reasons and offline software integration, they need

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 16:11

    Yes. As long as you have the php_mssql extension on your server, you can use the following common functions:

    // Connect to mssql server
    $handle = mssql_connect($host, $user, $pass) or die("Cannot connect to server");
    
    // Select a database
    $db = mssql_select_db($dn_name, $handle) or die("Cannot select database"); 
    
    // Execute a query
    $query = "SELECT * FROM users WHERE lname = 'Smith'";
    $result = mssql_query($query);
    
    // Iterate over results
    while($row = mssql_fetch_array($result)) { echo $row["id"]; }

    Note: From PHP 5.3 this extension is not included (and probably not maintained). You can download and add it manually, or better use Microsoft drivers.

提交回复
热议问题