警告:sqlsrv_query()期望参数1为资源,字符串给定[关闭]

Setup

MS IIS server

MSSQL DB Server

PHP

Error

Warning: sqlsrv_query() expects parameter 1 to be resource, string given in C:\inetpub\wwwroot\creating_new_table.php on line 36
Table creation failed with error:

Fatal error: Call to undefined function sqlsrv_get_last_message() in C:\inetpub\wwwroot\creating_new_table.php on line 39

Code

$serverName ="NAME\SQLEXPRESS";
$usr="sa";
$pwd="pasw";
$db="DBNAME";

$connectionInfo = array("UID" => $usr, "PWD" => $pwd, "Database" => $db);

$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn )
{
    echo "Connected";
}
else
{
    echo "Error";
    die( print_r( sqlsrv_errors(), true));
}

$sql = "CREATE TABLE fyi_links ("
    . " id INT NOT NULL VARCHAR (6)" 
    . ", url VARCHAR(80) NOT NULL"
    . ", notes VARCHAR(1024)"
    . ", counts INT"
    . ", time DATETIME"
    . ")";
$res = sqlsrv_query($sql,$conn);
if (!$res) {
    print('Table creation failed with error:
');
    print("   ".sqlsrv_get_last_message()."
");
}
else {
    print("Table fyi_links created.
");
}  

mssql_close( $conn);

Connection is fine but something happens with my create table script.

$res = sqlsrv_query($sql,$conn); should be $res = sqlsrv_query($conn, $sql);

See the manual http://us3.php.net/manual/en/function.sqlsrv-query.php