0

我收到此错误

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ''., SQL state 37000 in SQLExecDirect in D:\wamp\www\STAPP\sys_admin\1.php on line 23

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ''., SQL state 37000 in SQLExecDirect in D:\wamp\www\STAPP\sys_admin\1.php on line 23


<?php

require_once("../includes/database_connection.php");
$conn=odbc_connect('stapp','','');

if ( isset( $_FILES['userfile'] ) )
{
$csv_file = $_FILES['userfile']['tmp_name'];

if ( ! is_file( $csv_file ) )
exit('File not found.');

$sql = '';

if (($handle = fopen( $csv_file, "r")) !== FALSE)
{
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
  {


$sql = "INSERT INTO `table` SET `column0` = '$data[0]',

`column1`=            '$data[1]', `column2` = '$data[2]';";

   $rs1=odbc_exec($conn,$sql);

  }
  fclose($handle);
}

// Insert into database

//exit( $sql );
exit( "Complete!" );
}
?>

第 23 行是 $rs1=odbc_exec($conn,$sql);

任何人都可以在sql语句中帮助我吗

4

1 回答 1

1

插入记录的 SET 方式不是标准的SQL。最好采用标准方式

INSERT into table (column0, column1, column2) values 
('$data[0]', '$data[1]', '$data[2]');
于 2013-02-20T06:39:06.730 回答