我在 CentOS 服务器上通过 unixODBC 和 FreeTDS 建立了到 Sybase 数据库的连接。 (我不拥有 Sybase 服务器,我只有一个具有只读权限的帐户)
TL;DR: 我可以同时连接 odbc_pconnect
和 PDO,但是当我执行相同的查询时,odbc_pconnect
工作,而 PDO 返回错误
全文:我使用 odbc_pconnect
创建了一个简单的测试
$query = "select COUNT(*) from table_name";
$conn = odbc_pconnect("myDSN", 'myusername', 'mypassword');
if(!$conn)
die("Connection failed");
if($result = odbc_exec($conn, $query))
{
odbc_result_all($result);
}
上面的代码有效,我得到了我想要的计数。
然后我尝试使用PDO
$connectionstring = "odbc:myDSN;";
try {
$db = new \PDO(
$connectionstring , 'myusername', 'mypassword');
} catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
$rs = $db->query($query);
debug($db->errorInfo());
连接已建立(没有“连接失败”错误)但随后服务器返回错误:
[FreeTDS][SQL Server]ASA Error -121: Permission denied: you do not have permission to use the "CREATE PROCEDURE" statement (SQLExecute[262] at /builddir/build/BUILD/php-5.4.16/ext/pdo_odbc/odbc_stmt.c:254)
好吧,如您所见,我的查询并未尝试创建任何过程
我尝试了不同的连接字符串,但结果没有改变
我想问题出在我的 odbc 和 freeTDS 配置上,而不是在 PHP 上。但问题仍然存在:为什么会有不同的行为?
编辑 我在尝试从控制台访问数据源时发现了同样的问题:如果我尝试使用 tsql
tsql -S myDSN -U myusername -P mypassword
我可以执行查询。但是当我使用 isql
访问时:
isql -v myDSN myusername mypassword
我得到与上面相同的错误:
[42501][FreeTDS][SQL Server]ASA Error -121: Permission denied: you do not have permission to use the "CREATE PROCEDURE" statement [ISQL]ERROR: Could not SQLExecute
我想这与this有关
附言 我正在使用 cakephp 3.1.11
最佳答案
您可能不会创建过程,但 CakePHP 可以在后台为您创建过程。如果您只有读取权限,则无法创建过程,source :
The following describes permission checks for create procedure (also when creating an extended procedure) that differ based on your granular permissions settings.:
Granular permissions enabled - you must have the create procedure privilege. You must have the create any procedure privilege to run create procedure for other users.
Granular permissions disabled - you must be the database owner or have the create procedure privilege.
关于php - odbc_pconnect 有效,但 PDO 给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36056336/