从Ubuntu和PHP访问Azure SQL服务器

时间:2013-11-01 01:44:16

标签: php sql-server tsql ubuntu azure

解决了几个初始错误后,我能够连接到服务器。我的问题是我似乎无法访问表格。

这是freetds.conf文件:

[azure]
host = name.database.windows.net
port = 1433
tds version = 8.0
database = databasename

这是我的PHP文件:

ini_set('display_errors', 1);
# Older FreeTDS installations need the FREETDSCONF Environment variable
putenv('FREETDSCONF=/etc/freetds.conf');
# Current release of FreeTDS uses the FREETDS environment variable. So we set both to be sure
putenv('FREETDS=/etc/freetds.conf');

$server = 'azure';
$link = mssql_connect($server, 'username@name', 'password');

if (!$link) {
    die('<br/><br/>Something went wrong while connecting to MSSQL');
}
else {

$query_result = mssql_query('SELECT * FROM information_schema.tables');

echo "<pre>";
while($row = mssql_fetch_array($query_result)){
    print_r($row).'<br/>';
}
echo "</pre>";

mssql_free_result($query_result);
mssql_close($link);
}

这是在浏览器上显示以下内容:

Array
(
[0] => master
[TABLE_CATALOG] => master
[1] => dbo
[TABLE_SCHEMA] => dbo
[2] => slo_service_dimensions
[TABLE_NAME] => slo_service_dimensions
[3] => VIEW
[TABLE_TYPE] => VIEW
)
Array
(
[0] => master
[TABLE_CATALOG] => master
[1] => dbo
[TABLE_SCHEMA] => dbo
[2] => slo_dimension_settings
[TABLE_NAME] => slo_dimension_settings
[3] => VIEW
[TABLE_TYPE] => VIEW
)

还有更多。但没有关于我的实际表格。现在,如果我将PHP更改为:

$result = mssql_query('select Email from Profile');
while($row = mssql_fetch_array($result))
echo $row["Email"] .'<br/>';

我在浏览器中收到以下内容:

Warning: mssql_query(): message: Invalid object name 'Profile'. (severity 16) in file.php on line 23
Warning: mssql_query(): General SQL Server error: Check messages from the SQL Server (severity 16) in file.php on line 23
Warning: mssql_query(): Query failed in file.php on line 23
Warning: mssql_fetch_array() expects parameter 1 to be resource, boolean given in file.php on line 25

如果我将查询更改为:

,也会发生同样的情况
$result = mssql_query('select Email from dbo.Profile');

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

错误&#34;无效的对象名称&#39;个人资料&#39;&#34;表示正在建立连接并且登录成功。确保您登录的用户对Profile表具有适当的权限,而不仅仅是服务器。您可能需要将用户添加到datareader角色。