<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
I have reverted to the original subject - hope this is OK for
everyone - respond in the apology thread if not ;)<br>
<br>
<font class="Apple-style-span" face="arial, sans-serif"><span
class="Apple-style-span" style="border-collapse: collapse;">Stephen
wrote:</span></font><br>
<blockquote
cite="mid:BANLkTinPrzVOvEn=YFevKfTEurgjqQXNHg@mail.gmail.com"
type="cite">1.2 My website is wordpress, so i guess, like you say
i will have to work out what commands to query WP db.<br>
<br>
</blockquote>
This shell function returns the value of field $FLDNAME from the
first record in table $TBLNAME in database mysqldbname.<br>
<br>
func_queryMysql() {<br>
MUSER="myuser"<br>
MPASS="mypass"<br>
MHOST="localhost"<br>
DB="mysqldbname"<br>
FLDNAME="$1"<br>
TBLNAME="$2"<br>
MYSQL="$(which mysql)"<br>
QUERYSTR="SELECT $TBLNAME.$FLDNAME FROM $TBLNAME"<br>
GETVAL="$($MYSQL -u $MUSER -p$MPASS $DB -se "$QUERYSTR")"<br>
echo "$GETVAL"<br>
}<br>
<br>
Use the function like this :<br>
<br>
result=$(func_queryMysql field table)<br>
echo $result<br>
<br>
Bash is simply the wrong tool to be interacting with a mysql
database however, scripts will break as soon as you swear at them
with a $+=-!`"' or any other of a host of "special" characters. It
will also scramble your brains. Use php for working mysql. Bash is
good for the file and system donkey work though, so you need to call
your bash scripts from php using this:<br>
<br>
$command = "$SCRIPTSDIR/bashscript.sh";<br>
$shellOutput = shell_exec($command.' > /dev/null;
echo $?');<br>
<br>
Probably someone else has a better syntax that's just my newbie
hack...?<br>
<br>
A good principle with scripting is to use the use the right tool for
the job, for instance sending an email in bash is unreliable due to
bad headers and spam bins, and you never know if it really went
anywhere. Whereas using mutt is just like this:<br>
<br>
/usr/bin/mutt -H $HEADERFILENAME $ATTACHMENTNAME < $MESSAGE<br>
<br>
Good luck with the escaping\ escape\ characters, see you in the
asylum ;)<br>
<br>
Alan<br>
</body>
</html>