在解决了几个初始错误后,我能够连接到服务器。我的问题是我似乎无法访问这些表。
这是 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');
有任何想法吗?