LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-02-2006, 05:56 PM   #1
Julianus
Member
 
Registered: Nov 2003
Location: Germany
Distribution: Ubuntu 8.04
Posts: 39

Rep: Reputation: 15
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:

Code:
#!/usr/local/bin/php

<?php

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

   mysql_select_db("Eliza");

   $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:

Code:
$ vorbiscomment -l 01.ogg
title=Symphony
$
However, if I set the title to be the variable, it doesn't work:
Code:
echo exec ('vorbiscomment -w -t title=$row["Title"] 01.ogg');


$ vorbiscomment -l 01.ogg
title=[Title]
$
Also, it doesn't work like this:
Code:
$title=$row["Title"];
echo exec ('vorbiscomment -w -t title=$title 01.ogg');


$ vorbiscomment -l 01.ogg
title=
$
Apparently, the problem is how to declare the variable.
Any suggestions?
 
Old 08-02-2006, 11:51 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,246

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
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?
 
Old 08-03-2006, 02:35 AM   #3
smallville
Member
 
Registered: Dec 2005
Posts: 44

Rep: Reputation: 15
try this:

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

or

$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;
 
Old 08-03-2006, 02:09 PM   #4
Julianus
Member
 
Registered: Nov 2003
Location: Germany
Distribution: Ubuntu 8.04
Posts: 39

Original Poster
Rep: Reputation: 15
Thank you for your suggestion. This solved the problem:

$title=$row["Title"];
$composer=$row["Composer"];

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a row to another PHP script bahadur Programming 5 12-24-2011 01:07 AM
LXer: Title: PHP/MySQL Classifieds Script AddAsset1.php Script Insertion LXer Syndicated Linux News 0 07-02-2006 06:21 PM
script (or other) to pass variables to C++ program ngwenyama Programming 9 01-20-2005 09:54 PM
Import records to MySQL Database from a shell script chrisk5527 Linux - General 12 03-24-2004 09:49 PM
PHP Script to retrieve queries from log file saravanan1979 Programming 1 03-17-2002 08:13 AM


All times are GMT -5. The time now is 09:52 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration