title: Inserting csv file into SQL Server database table
body: <p>I am using the PHP code below to make bulk insert into database table in SQL Server. I already have a table called <code>ShopifyItem</code> (with 25 columns) but when I use this code I got </p>
  
  <blockquote>
    <p><em>Undefined offset: 24</em> </p>
  </blockquote>
  
  <p>error message and in <code>Item</code> table I only see 
   (26 row(s) inserted properly) even the csv file have more than 1,000 in row. </p>
  
  <p>Can anyone tell me what's wrong?</p>
  
  <p>PHP code:</p>
  
  <pre><code>$server = "**\**,1433";
  $connectionInfo = array( "Database"=&gt;"**", "UID"=&gt;"**", "PWD"=&gt;"**" );
  $conn = sqlsrv_connect( $server, $connectionInfo );
  if( $conn === false ) {
      die( print_r( sqlsrv_errors(), true));
  }
  $file_handle = fopen("Table.csv", "r");
  
  while (!feof($file_handle) ) {
  
  $line_of_text = fgetcsv($file_handle, 1024);
  
   $tsql = "INSERT INTO Item (Handle, Title, [Body(HTML)], Vendor, [Type], Tags, [Option1 Name],[Option1 Value], [Option2 Name], [Option2 Value], [Option3 Name], [Option3 Value], [Variant SKU], [Variant Grams], [Variant Inventory Tracker],[Variant Inventory Qty], [Variant Inventory Policy], [Variant Fulfillment Service], [Variant Price], [Variant Compare At Price], [Variant Requires Shipping], [Variant Taxable], [Image Src], HQID, WebPrice)
           VALUES ('$line_of_text[0]','$line_of_text[1]', '$line_of_text[2]', '$line_of_text[3]', '$line_of_text[4]', '$line_of_text[5]', '$line_of_text[6]', '$line_of_text[7]', '$line_of_text[8]', '$line_of_text[9]', '$line_of_text[10]', '$line_of_text[11]', '$line_of_text[12]', '$line_of_text[13]', '$line_of_text[14]', '$line_of_text[15]', '$line_of_text[16]', '$line_of_text[17]', '$line_of_text[18]', '$line_of_text[19]', '$line_of_text[20]', '$line_of_text[21]', '$line_of_text[22]', '$line_of_text[23]', '$line_of_text[24]' )"; 
  
  if( sqlsrv_query( $conn, $tsql))
  {
        echo "Statement executed.\n";
  } 
  else
  {
        echo "Error in statement execution.\n";
        die( print_r( sqlsrv_errors(), true));
  }
  
  } 
  </code></pre>