php - SQL Server Prepared Statement saying invalid column count -
so i'm working on project here , i"m trying prepared statement can handle odd objects slashes , not raw data comes through. however, when go execute statement provides same error on , on again:
sqlstate: 07002 code: 0 message: [microsoft][sql server native client 11.0]count field incorrect or syntax error
it says field count incorrect, checked variables , made sure supposed there, is. i'm little confused guess. note first time working sqlsrv prepared statements, awesome!
here code below:
<?php $servername = "localhost"; $connectioninfo = array( "database"=>"devel", "uid"=>"root", "pwd"=>""); $conn = sqlsrv_connect( $servername, $connectioninfo); $error_message = ""; $xml = trim(file_get_contents('/file.xml')); $xml = new simplexmlelement($xml); $truck_number; $date_time; $speed; $heading; $gps_quality; $latitude; $longitude; $location; $fix_type; $ignition; $gps_odometer; $gps_rolling_odometer; $performx_odometer; $performx_fuel; $performx_speed; $performx_idle; $packet_id; sqlsrv_begin_transaction($conn); $error_count = 0; $q = "insert eagle_devel.dbo.people_net (truck_number, date_time, speed, heading, gps_quality, latitude, longitude, location, fix_type, ignition, gps_odometer, gps_rolling_odometer, performx_odometer, performx_fuel, performx_speed, performx_idle, packet_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = sqlsrv_prepare($conn, $q, array(&$truck_number, &$date_time, &$speed, &$heading, &$gps_quality, &$latitude, &$longitude, &$location, &$fix_type, &$ignition, &$gps_odometer, &$gps_rolling_odometer, &$performx_odometer, &$performx_fuel, &$performx_speed, &$performx_idle, &$packet_id)); foreach($xml->loc_history $loc_history){ $truck_number = $loc_history->truck_number; $date_time = $loc_history->datetime; $speed = $loc_history->speed; $heading = $loc_history->heading; $gps_quality = $loc_history->gps_quality; $latitude = $loc_history->latitude; $longitude = $loc_history->longitude; $location = $loc_history->location; $fix_type = $loc_history->fix_type; $ignition = $loc_history->ignition; $gps_odometer = $loc_history->gps_odometer; $gps_rolling_odometer = $loc_history->gps_rolling_odometer; $performx_odometer = $loc_history->performx_odometer; $performx_fuel = $loc_history->performx_fuel; $performx_speed = $loc_history->performx_speed; $performx_idle = $loc_history->performx_idle; $packet_id = $xml->packet_id; if(sqlsrv_execute($stmt) === false){ $error_count++; if(($errors = sqlsrv_errors()) != null){ foreach($errors $error){ $error_message .= "sqlstate: ".$error['sqlstate']."<br>"; $error_message .= "code: ".$error['code']."<br>"; $error_message .= "message: ".$error['message']."<br><br>"; } } } } if($error_count) sqlsrv_rollback($conn); else sqlsrv_commit($conn); print $error_message; ?>
update : told try , initialize variables before hand did , this.
sqlstate: imssp code: -16 message: invalid php type parameter 1 specified.
i have no idea means i'm researching.
Comments
Post a Comment