一般SQL Server错误:检查来自SQL Server的消息[207](严重性16)

elcex8rz  于 2022-11-21  发布在  SQL Server
关注(0)|答案(1)|浏览(658)

我面临的问题,而试图连接到我的SQL服务器计算机与下面的代码。

$hostname = '10.11.22.33';                 
$username = 'siddharth';
$password = '1234';
$dbname = 'airport';
$port='1433';

$dbh = new PDO("dblib:host=$hostname:$port;dbname=$dbname;charset=UTF-8", $username, $password);
$arraykey=array_keys($data); 
$array=$data[$arraykey[0]]; 

try 
{
 //$count = $dbh->exec('INSERT INTO dbo.gmr(version,visitorId,dwellTime,poiId,srId,zoneId,poiProximityConfidence,zoneProximityConfidence,poiPresenceConfidence,zonePresenceConfidence,normalizedTime) VALUES ("' . implode('", "', $array) . '")' ) or die(print_r($dbh->errorInfo(), true)); 
 // Changed from double quotes to single while inserting VALUES
 $count = $dbh->exec("INSERT INTO dbo.gmr(version,visitorId,dwellTime,poiId,srId,zoneId,poiProximityConfidence,zoneProximityConfidence,poiPresenceConfidence,zonePresenceConfidence,normalizedTime) VALUES ('" . implode("', '", $array) . "')" ) or die(print_r($dbh->errorInfo(), true)); 
 $dbh = null;
echo 'Data Successfully inserted!!<br />';
}
catch(PDOException $e)
{
    echo $e->getMessage();
}

当我执行这个脚本时,我得到下面的错误。
数组([0] =〉HY 000 [1] =〉207 [2] =〉常规SQL Server错误:检查来自SQL Server的消息[207](严重级别16)[] [3] =〉-1 [4] =〉16)
如果我print_r $dbh,我只得到PDO()
PDO插件有什么问题。
听起来怪怪的,跟我玩了一会儿。
但是,我在下面的脚本中使用的同一个pdo对象用于选择查询,我得到了“它正在工作”的消息!!

$hostname = '10.11.22.33';                 
$username = 'siddharth';
$password = '1234';
$dbname = 'airport';
$port='1433';
try {
$dbh = new PDO("dblib:host=$hostname:1433;dbname=$dbname;charset=UTF-8", $username, $password);

$sql = "SELECT 'It is working' AS name";
foreach ($dbh->query($sql) as $row) {
    print $row['name'] . "\n";
}
} catch (PDOException $ex) {
print $ex->getMessage();
}
ukxgm1gy

ukxgm1gy1#

尝试插入带有单个quotes的硬编码值,但被插入。
因此将insert语句中的引号从
'INSERT INTO gmr VALUES(“' .内聚('“,“',$array). '“)')到
“插入到gmr值中('“. implode(“','“,$array).“')”)

相关问题