Running sql scripts in php sqlconsole / detecting user input
Posted: Sat Apr 17, 2010 12:22 am
Hello.
I'm working on an sql console in php that uses a mysql driver. I am using the gnu readline library to handle user input, however I am having trouble running sql scripts, i.e:
the test file has the following line of code with no returns afterwards:
[text]select * from country limit 8;
[/text]
The console itself works fine however when I run the code above I get:
[text]SQLConsole> select * from country limit 8; -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> ->[/text]
I was able to solve this problem in my java version by adding the following to main:
I put this as the first line in the main method so that I would know if input will be from keyboard or redirected file.
I haven't been able to find an equivalent solution for php.
Can anyone help me out?
I'm working on an sql console in php that uses a mysql driver. I am using the gnu readline library to handle user input, however I am having trouble running sql scripts, i.e:
Code: Select all
php sqlconsole.php < test.sql[text]select * from country limit 8;
[/text]
The console itself works fine however when I run the code above I get:
[text]SQLConsole> select * from country limit 8; -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> ->[/text]
I was able to solve this problem in my java version by adding the following to main:
Code: Select all
boolean isKeyboardInput = System.in.available() == 0;I haven't been able to find an equivalent solution for php.
Can anyone help me out?