PHP - SQLSRV连接

时间:2015-07-01 11:42:25

标签: php sql-server xampp sqlsrv

最近我一直在使用PHP创建一个Web应用程序并使用MySQL,但几天前我被告知要迁移到SQL Server。

问题是我在编程时知道,我对SQLServer一无所知。

我花了一个上午成功安装SQLServer的xampp扩展,然后试图寻找连接函数,预处理语句......

http://php.net/manual/en/funcref.php我发现了这些功能,我做了类似的事情:

$DB_Server = "serverName\sqlexpress";
$DB_User = "userName";
$DB_Password = "j$oeisk="; //The Password is something like this
$DB_Name = "databaseName";

global $DB_Server, $DB_User, $DB_Password, $DB_Name;

$connectionInfo = array("UID" => $DB_User, "PWD" => $DB_Password, "Database"=>$DB_Name); 
$conn = sqlsrv_connect($DB_Server, $connectionInfo);

$result = NULL;

if ($conn)
{   
    $conn->set_charset("utf8");

    if (($Profile == 1) && ($stmt = sqlsrv_prepare($conn, "SELECT name FROM users")))
    {               
        if(sqlsrv_execute( $stmt ))
        {           
          echo "<select name='workers'>";

          while($result = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
          {
                echo "<option value=",$result['nome'],">",$result['nome'],"</option>";
          }

          echo "</select>";                         

          sqlsrv_free_stmt( $stmt );
         }

    sqlsrv_close( $conn );
    }   
}

但它告诉我这个:

Notice: Undefined variable: oeisk in C:\xampp\htdocs\markings\database.php

我一直在寻找解决方案,但我甚至没想到它是如何完成的

我感谢任何帮助

0 个答案:

没有答案