Thursday 15 March 2012

php - Save mysql query into database -



php - Save mysql query into database -

i trying allow users (in place of work) run query, , if choose, save database can run 1 time again later single click (like if updating database). having problem this, though. running query isn't issue, query doesn't save correctly. query this:

load info infile 'path/to/file/file.txt' table table fields terminated '\t' lines terminated '\n';

i can save database correctly if escape backslashes when typing out query, causes query run incorrectly on submit. wondering if there way can automatically escape backslashes. or easier/better separate 2 features? if more info needed allow me know, , in advance.

i did tinkering, , got it. here solution came with:

first, used str_replace on update.

$q = str_replace(array("\t", "\n"),array("\\t","\\n"), $_post['update']);

then, prepared suggested.

if($stmt = $con->prepare("insert queries (query_name, query, description) values (?, ?, ?);")){ $stmt->bind_param('sss', $qn, $q, $qd); $stmt->execute(); $stmt->store_result(); $stmt->close(); }

finally, ran mysqli_multi_query (because there more 1 query in submission, caused fail) run query(s) user puts in.

$query = mysqli_multi_query($con, $q);

thanks offered suggestions!

php mysql sql

No comments:

Post a Comment