Running sql scripts in php sqlconsole / detecting user input

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
murrieta
Forum Newbie
Posts: 1
Joined: Fri Apr 16, 2010 11:27 pm

Running sql scripts in php sqlconsole / detecting user input

Post by murrieta »

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:

Code: Select all

php sqlconsole.php < test.sql
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:

Code: Select all

 boolean isKeyboardInput = System.in.available() == 0;
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?
Post Reply