I have error with insert multi column data into SQL Server database with PHP
php Code:
<?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)
The line that the error was pointed out to him:
die('Error: ' . sqlsrv_errors());
$para = array
why are those in " .... "
? 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.