致命错误:访问SQL Server表时

时间:2018-08-27 07:47:59

标签: php sql-server-2014-express

通过PHP脚本从SQL Server 2014访问数据时,我遇到致命错误。

Fatal error: Uncaught PDOException: SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The SELECT permission was denied on the object 'test_table', database 'test_db', schema 'dbo'.

我的PHP脚本是

$server = 'KESAVATDL\SQLEXPRESS';    //KESAVATDL\SQLEXPRESS
$dbname = "acharya_db";
$usname="";
$passwd="";

try
{
    $con=new PDO("sqlsrv:Server=$server;Database=$dbname",$usname,$passwd);


    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    echo "Connected Successfully.";
}
catch(PDOException $e)
{
   echo "Connection failed: " . $e->getMessage();
}

$sql = "SELECT * FROM test";

foreach ($con->query($sql) as $row) {
   print_r($row);
}

0 个答案:

没有答案