-   Programming (
-   -   PHP script to retrieve records from MYSQL db and pass them to an external program (

Julianus 08-02-2006 05:56 PM

PHP script to retrieve records from MYSQL db and pass them to an external program
I'm trying to write a small shell script that access my database, retrieves some records and use them to edit the tags of my ogg files. I use exec to execute vobiscomment. If the title is not a variable, vorbiscomment renames the tag:




  $link = mysql_connect("localhost","root","");


  $query = "select * from Eliza order by Title_ID limit 5";
  $result = mysql_query($query) or die("Could not: $query");

  while ($row = mysql_fetch_array($result))


print $row["Title"];
print "\n";

echo exec ('vorbiscomment -w -t title=Symphony 01.ogg');
print "\n";
print "\n";



The result is as follows:


$ vorbiscomment -l 01.ogg

However, if I set the title to be the variable, it doesn't work:

echo exec ('vorbiscomment -w -t title=$row["Title"] 01.ogg');

$ vorbiscomment -l 01.ogg

Also, it doesn't work like this:

echo exec ('vorbiscomment -w -t title=$title 01.ogg');

$ vorbiscomment -l 01.ogg

Apparently, the problem is how to declare the variable.
Any suggestions?

chrism01 08-02-2006 11:51 PM

Well, in shell and Perl single quotes mean don't interpolate vars ie don't cvt vars to values. double quotes do allow interpolation. could be the same for php?

smallville 08-03-2006 02:35 AM

try this:

echo exec ('vorbiscomment -w -t title='.$row["Title"].'01.ogg');


$code = exec ('vorbiscomment -w -t title='.$row["Title"].'01.ogg');
echo $code;

or if if still won't work, try this:

$com = 'vorbiscomment -w -t title='.$row["Title"].'01.ogg';
$code = exec($com);
echo $code;

Julianus 08-03-2006 02:09 PM

Thank you for your suggestion. This solved the problem:


$vorbis="vorbiscomment -w -t composer='$composer' -t title='$composer - $title' 01.ogg";
echo exec ($vorbis);

All times are GMT -5. The time now is 01:30 PM.