Skip to content

Instantly share code, notes, and snippets.

@nkkarthik
Last active August 29, 2015 14:19
Show Gist options
  • Save nkkarthik/5bedf8cbbc176194e4e0 to your computer and use it in GitHub Desktop.
Save nkkarthik/5bedf8cbbc176194e4e0 to your computer and use it in GitHub Desktop.
php runs mssql query on command line and returns the results
<?php
$server = $_POST['server'];
$db = $_POST['db'];
$raw_query = $_POST['query'];
$trimmed_query = trim(preg_replace('/\s+/', ' ', $raw_query));
$cmd = 'sqlcmd -S ' . $server . ' -d ' . $db . ' -Q "' . $trimmed_query . '"';
echo shell_exec($cmd);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment