i have a script to synchronize/output my mysql database with another server.
i know how to call this SQL query in shell. however, is it possible to convert this script’s output from php to shell script to keep the format shown below (basically values separated by “|” and some URLs)? i need the output in this specific format shown below:
$sql=mysql_query("SELECT a, b, c, d, e FROM tableA LEFT JOIN tableB USING (a)");
while ($res=mysql_fetch_array($sql))
{
echo $res['a']."|".$res['b']."|".$res['c']."|http://www.url.com/".$res['e']."/".$res['a'].".php|http://www.url.com/link/".urlencode($res['b'])."\n";
}
thanks
You can do all these concatenation with a simple Query passed to mysql from command line :
The first SET, set the pipe as concat operator in MySQL so you can join string with SQL standard double pipe instead of using the annoying CONCAT function … After that the result set is a concatenation of strings directly in the SQL query.
In this way you can execute this command from a bash script without the necessity to have a php interpreter installed …