问题描述
一个客户端建立在Azure云的SQL数据库。我试图用PDO连接,但只要我试图访问一个表的数据,我得到一个错误信息。
A client has set up an SQL database on the Azure cloud. I am trying to use PDO to connect, but as soon as I try to access a table's data, I get an error message.
我的code连接:
try {
$db = new PDO('sqlsrv:server=tcp:serverid.database.windows.net,1433;Database=testdb','user','pass');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
echo "Error " . $e->getMessage();
}
这工作正常,并不会产生错误。我的code插入...
This works fine and produces no errors. My code to insert...
try {
$sql = "INSERT INTO tablename (introduction) VALUES (:introduction)";
$q = $db->prepare($sql);
$q->execute(array(':introduction'=>'hi'));
} catch (Exception $e) {
echo "Error " . $e->getMessage();
}
我从那个以下错误
I get the following error from that
Error SQLSTATE[42S02]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'tablename'.
表名肯定是确实存在的表。我们已经检查权限和不相信它是。我卡住了。 PDO是新的给我,所以我不知道是否有明显的东西我已经错过了做??
Tablename is definitely a table which does exist. We have checked permissions and don't believe it's that. I am stuck. PDO is new to me so I don't know if there's something obvious I've missed??
推荐答案
尝试把表名格式为:
dbname.tablename
不是最好的解决方案,但它确实为我工作。
Not the best solution but it did work for me.
这篇关于PHP PDO连接到SQL Azure的 - 无效的对象名称[表]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!