Accessing mysql via dos

 
Post new topic   Reply to topic    Aprelium Forum Index -> Databases
View previous topic :: View next topic  
Author Message
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Thu Oct 05, 2006 12:32 am    Post subject: Accessing mysql via dos Reply with quote

This may be a daft question but to access your mysql data from a batch file would you just prefix the command with the mysql bin file?

To explain, I am trying to put together a batch that will run every 5 mins and read my database and output the number of users online and the last message posted and squirt it out to my LED display. I was going to do this from a web page then I realised I would have to have the page active all the time and do a meta refresh, much better then to have a scheduled job me thinks.

Hope this isn't too off topic for this forum.

thanks Paul
Back to top View user's profile Send private message Visit poster's website
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Thu Oct 05, 2006 7:57 am    Post subject: Reply with quote

This is how I would do it:

"C:\Program Files\PHP5\php-cgi.exe" "C:\path\to\your\script.php"

Then just make the script do the database stuff
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Thu Oct 05, 2006 10:24 am    Post subject: Reply with quote

What a fantastic solution!

Thanks mate
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Oct 05, 2006 12:28 pm    Post subject: Reply with quote

Mikor wrote:
This is how I would do it:

"C:\Program Files\PHP5\php-cgi.exe" "C:\path\to\your\script.php"

Then just make the script do the database stuff


It is even better to use php.exe instead of php-cgi.exe. Actually php.exe in the preconfigured package is the CLI version (Command Line Interface) version of PHP which is meant to be run without a web server and directly from the command line.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Thu Oct 05, 2006 2:00 pm    Post subject: Reply with quote

Thanks Aprelium :)

I have another quick question, i know how to display all my records from mysql DB table, but how to I display just the most recent one, all records have an ID number so I think I'm on the right track.

Paul
Back to top View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Oct 05, 2006 4:41 pm    Post subject: Reply with quote

I use the command line method for my uptime scripts. It also runs my daily maintenance script but thats just a bat file, its not php unlike the uptime script.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Oct 06, 2006 1:50 pm    Post subject: Reply with quote

PaulK,

Code:
SELECT * FROM table_name_goes_here ORDER BY id_column_name_goes_here DESC LIMIT 1


For an explanation of each keyword, please refer to http://dev.mysql.com/doc/refman/5.0/en/select.html .
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Fri Oct 06, 2006 2:45 pm    Post subject: Reply with quote

That's the bugger, thanks aprelium!
Back to top View user's profile Send private message Visit poster's website
F.Boyce
-


Joined: 11 Oct 2011
Posts: 2
Location: Madagascar

PostPosted: Fri Oct 14, 2011 2:27 am    Post subject: Accessing mysql via dos Reply with quote

can think of is when that table is the parent of another table and the child table wants, for some reason, to minimize the size of its FK to the parent

for example,

team_player teamid, playerid
team_player_roster teamid, playerid, startdate, enddate
Back to top View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Toasty
-


Joined: 21 Feb 2008
Posts: 295
Location: Chicago, IL

PostPosted: Sun Oct 23, 2011 2:37 am    Post subject: Reply with quote

Try this too:

SELECT COUNT(*) FROM Users_Table_Here WHERE user_online_flag = '1';

Assuming you have a 0/1 flag for the online status, but more likely there will be a date that you'll use there (i.e. last_action_time > " . (time()-1800) . ") will show users online in the last half hour if you're using PHP and the last_action)time is stored as a Unix timestamp.
_________________
Portfolio: Robert Lerner
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Databases All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group