1

I use MariaDB and I access my database from terminal. Is it possible to get a value and use it as a query in terminal?

The website has a form and the value entered in one field will be the query used. I use php to connect the database and html.

How can I use the value from the form as a query, and pull the table that is produced in the terminal to display on a website?

Andrew Serra
  • 153
  • 14
  • 1
    its very simple, you directly prepare your statement from your form. write your query using form elements like you can use form element to enter query, enter parameters and data and submit that form to db via php. make sure about sql injection by using pdo/mysqli prepared statements. Its not a big deal just get your form value using $_post or $_get according to your form and place that value in your query. – BetaDev Dec 24 '16 at 20:04

1 Answers1

0

To read the output of a process, popen() is the way to go. Your script will run in parallel with the program and you can interact with it by reading and writing it's output/input as if it was a file.

But if you just want to dump it's result straight to the user you can cut the crap and use passthru():

echo '<pre>';
passthru($cmd);
echo '</pre>';

Now if you want to display the output at run time as the program goes, you can do this:

while (@ ob_end_flush()); // end all output buffers if any

$proc = popen($cmd, 'r');
echo '<pre>';
while (!feof($proc))
{
    echo fread($proc, 4096);
    @ flush();
}
echo '</pre>';

-- I just copied that from Havenard's (https://stackoverflow.com/users/156811/havenard) reply on PHP reading shell_exec live output. I hope it helps.

Community
  • 1
  • 1
MAMEEN
  • 1
  • 1