[英]Error with insert into sql server database with php
I have error with insert multi column data into SQL Server database with PHP 使用PHP将多列数据插入SQL Server数据库时出现错误
php Code: 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";
?>
Result: php error code (Array to string conversion on line 52) 结果: php错误代码 (第52行上的数组到字符串的转换)
The line that the error was pointed out to him: 向他指出错误的那一行:
die('Error: ' . sqlsrv_errors());
$para = array
why are those in " .... "
? $para = array
为什么" .... "
中的那些? This is not array, this is string. 这不是数组,这是字符串。 Delete
"
on both sides. It will be like: 在两边都删除
"
,就像:
$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.