我正在尝试将数据插入到 SQL Server 中的数据库表中。我能够连接到数据库并在插入时收到以下错误:
Errors: Array ( [0] => Array ( [0] => 42S02 [SQLSTATE] => 42S02 [1] => 208 [code] => 208 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'dbo.Salesforce'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'dbo.Salesforce'. ) )
为了简单起见,我硬编码了需要插入表中的值(而不是选择表单提交):
/*Insert data.*/
$insertSql = "INSERT INTO dbo.Salesforce (ID,Name, Company, Email, Phone, Assets, Comm, Capability)
VALUES (?,?,?,?,?,?,?,?)";
/* Construct the parameter array. */
$ID = 5;
$Name = "Sarah";
$Company = "Track24";
$Email = "xxx@live.com";
$Phone = "+xxxxxx";
$Assets = "Vehicles";
$Comm = "GSM";
$Capability = "IVMS";
$params1 = array($ID,
$Name,
$Company,
$Email,
$Phone,
$Assets,
$Comm,
$Capability);
$stmt = sqlsrv_query($conn, $insertSql, $params1);
if($stmt === false)
{
die('Errors: ' . print_r(sqlsrv_errors(), TRUE));
}
else
{
echo '<br clear="all"><label style="color:red;">Thank you for your details.</label>';
}
上面调用的字段并不是表的所有字段。还有一些,但由于它们允许null
值,所以我没有包括它们。我已经用谷歌搜索了这个错误,但无法理解它的实际含义以及问题出在哪里!任何指针?
编辑1:通过以下方式成功连接:
/* Specify the server and connection string attributes. */
$serverName = "xxxx-PC\SQLExpress";
$connectionOptions = array("Database"=>"Salesforce");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}