Executing PHP code from a command line

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
Sniper007
Forum Newbie
Posts: 17
Joined: Tue May 11, 2004 8:43 pm

Executing PHP code from a command line

Post by Sniper007 »

Is there any way to execute a chunk of PHP code (to alter an SQL database I have) using a command line? Like, is there some php.exe I can run with some parameters or something?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Yes, read more here:

http://www.php.net/features.commandline

also i found this in the comments:
Just a note for people trying to use interactive mode from the commandline.

The purpose of interactive mode is to parse code snippits without actually leaving php, and it works like this:

[root@localhost php-4.3.4]# php -a
Interactive mode enabled

<?php echo "hi!"; ?>
<note, here we would press CTRL-D to parse everything we've entered so far>
hi!
<?php exit(); ?>
<ctrl-d here again>
[root@localhost php-4.3.4]#

I noticed this somehow got ommited from the docs, hope it helps someone!
Post Reply