More information about the Underscore mailing list

[_] php and mysql loading sql query from file

rick hurst rickhurst at
Mon Oct 6 11:52:46 BST 2003

From: Oliver Humpage <oliver at>

> Could you use PHP to run a shell command, e.g.
> $result = `mysql -u username --password=yourpass dbname <
> /path/to/my_query.sql`;
> Although you'd end up with your password visible via ps -aux. Ick.

Ick indeed!

From: "James Thorpe" <james at>

> I'm not aware of any functions in PHP that would let you call mysql in
> this way. The best thing you could probably do is write a function that
> opens a file, reads its contents and returns it as a string, then just
> call it like:
> mysql_query(filestring("/path/to/query.sql"));

cheers for your suggestions, looks like i'll have to get PHP to do the file reading, I was just trying to find a way that the sql query files would be sitting securely on the database server and the php account (running on a seperate box) would have no direct access to the files, other than the file names and telling mysql to execute their content.

never mind, i'm probably getting too carried away with the security model!

Rick Hurst
Web Developer