note 77945 added to function.system
| From: | toby at globaloptima dot co dot uk | Date: | Thu, 20 Sep 2007 21:16:11 +0000 |
| Subject: | note 77945 added to function.system | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130640@lists.php.net to get a copy of this message | ||
Regarding Billybob's comment about multi-line system commands like this:
$commandeDB1 = system ("cd \
cd mysql
cd bin
mysql -uroot -pedfdiver -P3307
use diver_1
insert into cdn_flv_8(flv_file,cdn_dn_or_ip,video_path,flv_groups
values('$fichier','130.98.61.32','/diver_edf/video_1/','0');");
First things first, this kind of mysql interaction should be taken care of with the in-built mysql
or mysqli PHP libraries, it make much more sense when you see it, loads and loads of tutorials
online about this exact subject:
http://php.net/mysql
See how you can do exactly the same thing without using the system command:
$link = mysql_connect('localhost', 'root', 'edfdiver');
mysql_select_db('diver_1')
mysql_query("your insert sql here");
mysql_close($link);
Also you no longer rely on MySQL being located in a certain folder, your script is cross-platform,
easier to understand and generally far more robust.
Regarding multi-line statements using the system function, the only way I've done this in the
past is to separate each command with a semi-colon which in some cases is useful but most of the
time seems to be a really bad way of doing things (this is using Linux, BASH Shell, I expect Windows
has similar mechanism).
Note that you don't seem to be able to set shell variables either, again using BASH:
x=10;echo $x
This works on the command line, running via system prints an empty line, may be possible but
I've not managed it yet.
Also in your example, commands 1,2,3 and 4 are for the Operating System whilst commands 5 and 6 are
for MySQL, try putting a semi-colon between each of your commands to see what happens.
My advice, if you are new-ish to PHP, is to try and avoid the system/exec/passthru functions and
stick with in-built PHP libraries where-ever possible, most things you want to do can be handled by
these libraries.
And additions to this are welcome, I'm no expert, just a few things I've noticed.
Toby
----
Server IP: 194.145.210.3
Probable Submitter: 81.129.108.225
----
Manual Page -- http://www.php.net/manual/en/function.system.php
Edit -- https://master.php.net/note/edit/77945
Del: integrated -- https://master.php.net/note/delete/77945/integrated
Del: useless -- https://master.php.net/note/delete/77945/useless
Del: bad code -- https://master.php.net/note/delete/77945/bad+code
Del: spam -- https://master.php.net/note/delete/77945/spam
Del: non-english -- https://master.php.net/note/delete/77945/non-english
Del: in docs -- https://master.php.net/note/delete/77945/in+docs
Del: other reasons-- https://master.php.net/note/delete/77945
Reject -- https://master.php.net/note/reject/77945
Search -- https://master.php.net/manage/user-notes.php