[英]Error with insert into sql server database with php
使用PHP將多列數據插入SQL Server數據庫時出現錯誤
php代碼:
<?php
$serverName = "GHAREBAGHI\sqlexpress, 1433";
$connectionInfo = array( "Database"=>"PwKara", "UID"=>"test","PWD"=>"100100");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
} else {
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$tsql= "INSERT INTO Requests
(EMP_NO ,SubmittedDate ,Type ,StartDate ,EndDate ,StartHour ,EndHour
,Duration ,SubmittedByEmployeeID ,OperationsID ,Description ,CurEmp_NO ,AcceptCode ,IsWardenCheck ,RequestStatus ,IOStatus ,CurSection)
VALUES
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$para = array("93229 ,'2016-10-19 09:23:48.850' ,54 ,'2016-10-19 09:23:48.850' ,'2016-10-19 09:23:48.850' ,2359 ,2359 ,2 ,83229 ,3 ,'php test' ,8813 ,0 ,0 ,0 ,0 ,6");
if (!sqlsrv_query($conn, $tsql, $para)){
die('Error: ' . sqlsrv_errors());
}
echo "1 record added";
?>
結果: php錯誤代碼 (第52行上的數組到字符串的轉換)
向他指出錯誤的那一行:
die('Error: ' . sqlsrv_errors());
$para = array
為什么" .... "
中的那些? 這不是數組,這是字符串。 在兩邊都刪除"
,就像:
$para = array(93229, '2016-10-19 09:23:48.850', 54, '2016-10-19 09:23:48.850', '2016-10-19 09:23:48.850', 2359, 2359, 2, 83229, 3, 'php test', 8813, 0, 0, 0, 0, 6);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.