The below is the php code i am using
$file_handle = fopen("products.csv", "r");
$fname = "products.csv";
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
$server = "**\******,1433";
$connectionInfo = array( "Database"=>"******", "UID"=>"***", "PWD"=>"*******" );
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$itemco = $line_of_text[0];
$sql = "SELECT quantity FROM Item WHERE itemlookupcode = '$itemco' ";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$icc = $row['quantity'];
$content = str_replace("$line_of_text[1]", "$icc", "$content");
}
}
$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);
str_replace
isn't working in the following instance:
$content = str_replace("$line_of_text[1]", "$icc", "$content");