LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-03-2004, 12:48 AM   #1
chynna_v
LQ Newbie
 
Registered: Sep 2004
Posts: 13

Rep: Reputation: 0
How to pass mysql query to a variable?


Hi can somene help me how to pass the output of an mysql query to a variable?

for ex.
==========================================================
#!/bin/sh
echo select count(*) from out where bfr_id=1 and status=0' | mysql -uroot
===========================================================
output is
count(*)
47568

i try to do this...
===============================================================
#!/bin/sh
DBS='echo select count(*) from out where bfr_id=1 and status=0' | mysql -uroot
echo $DBS
================================================================

nut nothing happens...what i want is to pass the value of "count(*)" to the variable of DBS and then prints it...

can you please help

thanks a lot...
 
Old 09-03-2004, 04:19 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
You don't indicate the database name, and don't use the inversed quotes, try :

DBS=`"echo select count(*) from out where bfr_id=1 and status=0" | mysql -uroot <database name>`

I assume there is no password for user root and the mysql server is running on your local machine
 
Old 09-03-2004, 04:26 AM   #3
chynna_v
LQ Newbie
 
Registered: Sep 2004
Posts: 13

Original Poster
Rep: Reputation: 0
i already tried that and got this error message:

found
Code:
./update_tempo.sh: line 1: echo select count(*) from out where bfr_id=1 and status=0: command not found
 
Old 09-03-2004, 04:38 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
I am sorry

try :
DBS=`echo "select count(*) from out where bfr_id=1 and status=0" | mysql -uroot <database name>`
 
Old 09-03-2004, 05:09 AM   #5
chynna_v
LQ Newbie
 
Registered: Sep 2004
Posts: 13

Original Poster
Rep: Reputation: 0
it worked!..thanks a lot..i knew that i was having problem where to put the inversed quotes...
 
  


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
Pass a variable as an agruement for cut chipmanchu Programming 1 05-25-2005 11:39 AM
php mysql variable arguments in query. ldp Linux - Software 0 10-26-2004 07:56 AM
How to pass env variable to KDE? koyi Linux - General 0 09-03-2003 03:29 AM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 03:12 PM
Pass text to variable Zed Linux - Software 6 05-12-2003 03:02 PM


All times are GMT -5. The time now is 05:40 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