尝试将新记录插入数据库时遇到问题。我认为问题在于位域。当我分配值 True 我得到这个错误:
Failed: Array ( [0] => Array ( [0] => 22018 [SQLSTATE] => 22018 [1]
=> 245 [code] => 245 [2] => [Microsoft][SQL Server Native Client 10.0]
[SQL Server]Conversion failed when converting the varchar value ' 1 '
to data type bit. [message] => [Microsoft][SQL Server Native Client 10.0]
[SQL Server]Conversion failed when converting the varchar value ' 1 ' to
data type bit. ) )
但如果我将其更改为 false 它可以工作。我将展示我的一些代码。我已经把它的大部分删掉了,因为我把它缩小到这个变量:
$active = True;
这是我的插入查询。
$sqlInsert = "INSERT INTO customers(
customerID,
registeredDate,
givenName,
familyName,
email,
password,
phone,
mobile,
property,
street,
locality,
town,
area,
postalCode,
active
)
VALUES(" .
$newUser . "," .
$date . ", ' " .
$given . " ', ' " .
$family . " ', ' " .
$email . " ', ' " .
$pwd . " ', ' " .
$phone . " ', ' " .
$mob . " ', ' " .
$property . " ', ' " .
$street . " ', ' " .
$locality . " ' , ' " .
$town . " ', ' " .
$area . " ', ' " .
$postalcode . " ', ' " .
$active . " ')";
$stmtInsert = sqlsrv_query($conn, $sqlInsert);