I have to update database manually alot, so I wrote an app that reads the first line of a csv file and creates the headers/tables for an insert or update statement. The next lines are the data in the file.
I build the statement like so
if ($checksite eq $none) { $insertsqlstatement = 'INSERT INTO database.database('; $x=0; foreach (@dbcolumn) { $insertsqlstatement = $insertsqlstatement . "@dbcolumn[$x]"; # if ($x != $numelements ) { $insertsqlstatement = $insertsqlstatement . ","; } # else { $insertsqlstatement = $insertsqlstatement . ') VALUES ('; } # $x=$x+1; } # $x=0; foreach (@dbcolumn) { $insertsqlstatement = $insertsqlstatement . '\'' . "@splitarray[$ +x]" . '\''; $splitstatement = $splitstatement . '$' .@dbcolumn[$x] ; # if ($x != $numelements) { $insertsqlstatement = $insertsqlstatement . ','; $splitstatement = $splitstatement . ','; } # else { $insertsqlstatement = $insertsqlstatement .')'; } $x=$x+1; } }
when I print the value of $insertsqlstatement is equal to INSERT INTO database.database(site_id, site_store_type, project, site_city, site_state, site_country, project_begin ) VALUES ('9999','SC OSR','Prebuild','Penfield','NY','US','8/8/2016 ')
I can copy it an it runs just fine in sql
Buy when i write from my sql statement it will not write sqlexec($insertsqlstatement);
But if i manualy set the value of $insertsqlstatement = "INSERT INTO database.database(site_id, site_store_type, project, site_city, site_state, site_country, project_begin ) VALUES ('9999','SC OSR','Prebuild','Penfield','NY','US','8/8/2016 ')";
The sqlexec($insertsqlstatement); executes and updates the database
In reply to building sql statement by mwill007
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |