I have been working on a project where I've been developing the MySQL commands interactively. I now want to run the MySQL commands using a PHP script. I do this by simply pasting in the MySQL commands and making them into a PHP string. Like this...
$queryStg = "
update table1 set col1 = 1;
drop table table2;
";
$sqlQuery = mysqli_multi_query($mysqliLink, $queryStg);
However I've always had to strip out the MySQL comments to get it to work. I'd prefer to retain these comments. Is there a way to do this?. I've tried adding '\n' at the end of each comment but I cant get this to work. E.g. if I run this it will come back with errors...
$queryStg = "
-- a mySQL comment
update table1 set col1 = 1;
--another comment
drop table table2;
";
$sqlQuery = mysqli_multi_query($mysqliLink, $queryStg);
Full code incase its useful
$mysqliLink = new mysqli ($host, $username, $password, $dbName);
$queryStg = "
-- a mySQL comment
update table1 set col1 = 1;
--another comment
drop table table2;
";
$sqlQuery = mysqli_multi_query($mysqliLink, $queryStg);
do {
if ( mysqli_error($mysqliLink) ) {
die("ERROR: " .
htmlspecialchars(mysqli_error($mysqliLink), ENT_QUOTES) .
"<br>\n");
}
echo mysqli_affected_rows($mysqliLink);
mysqli_use_result($mysqliLink);
$moreResults = mysqli_more_results($mysqliLink);
@mysqli_next_result($mysqliLink);
} while($moreResults);
Thanks