“不支持使用USE语句在数据库之间切换".运行查询时 [英] "USE statement is not supported to switch between databases" when running query

查看:499
本文介绍了“不支持使用USE语句在数据库之间切换".运行查询时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试选择具有php's标准mssql_select_db功能的数据库时出现以下错误:USE statement is not supported to switch between databases. Use a new connection to connect to a different Database. (severity 16).所以我很困惑从这里去哪里.

I get the following error when trying to select a database with php's standard mssql_select_db function: USE statement is not supported to switch between databases. Use a new connection to connect to a different Database. (severity 16). So i'm stumped as in where to go from here.

连接代码:

$link = mssql_connect('dsn', 'user@server', 'password');

if (!$link) {
   die('Unable to connect!');
}

if (!mssql_select_db('db', $link)) {
   die('Unable to select database!');
}

$result = mssql_query('SELECT * FROM yourtable');

while ($row = mssql_fetch_array($result)) {
   var_dump($row);
}

我的系统设置如下:

  • Ubuntu 12.10
  • PHP5
  • Apache2
  • freeTDS
  • unixODBC
  • SQL Azure

我也一直在关注指南.

推荐答案

针对@Pondlife的上述最后评论,由于他没有给出答案,因此我会为他完成,直到他自己发布为止.

In response to @Pondlife's last comment above and since he has not made it an answer I will do it for him until he posts it himself.

@Pondlife评论:

@Pondlife comment:

我自己没有使用Azure的经验,但是错误消息非常多 明确:您无法在SQL Azure中使用USE更改数据库.我不知道 如何或是否可以防止您的特定客户端库发出 USE命令,但我会尝试删除mssql_select_db()调用 并在ODBC DSN中指定正确的数据库名称. 希望可以将您直接连接到您想要的数据库 使用. - PondLife

I have no experience with Azure myself, but the error message is very clear: you can't change databases with USE in SQL Azure. I don't know how or if you can prevent your particular client libraries issuing a USE command, but I would try removing the mssql_select_db() call completely and specify the correct database name in your ODBC DSN. Hopefully that will connect you directly to the database you want to use. - PondLife

这篇关于“不支持使用USE语句在数据库之间切换".运行查询时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆