Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 02-12-2005, 07:16 PM   PM User | #1
ChrisOlver
New to the CF scene

 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ChrisOlver is an unknown quantity at this point
If row exists then update if not add new row.

Hi,

I am trying to make a script which gets a list of Ports and IPs from a remote mysql DB. With each result from the DB it is used to ping the servers to generate the stats..

I first tried doing this and let it scan the servers all on one page. I found this was a very slow result.. about 5 minutes to scan around 20 servers. My other option now is to get a cron job every 10 minutes to launch a script which scans the servers and then adds the result into a DB. This is where i get stuck! I want this all to be dynamic so I dont have to add and remove ips when the customer changes his mind about his CS source port. What I want to do is: If row exists then update that record with the status of the server, if the row doesnt exists then make one. The eventual displaying and scanning is in theory quite easy but the MYSQL (is record there) is where I get lost.. wondering if there is a shortcut without me needed to do a sql statement to see if it exsists.

How would i go round to do this?

Last edited by ChrisOlver; 02-12-2005 at 07:19 PM..
ChrisOlver is offline   Reply With Quote
Old 02-15-2005, 02:08 PM   PM User | #2
kenetix
New Coder

 
Join Date: Feb 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
kenetix is an unknown quantity at this point
mysql_num_rows

so lets say your row with ip 111.111.111.111 exists, just make a query like

PHP Code:
$query mysql_num_rows(mysql_query("SELECT * FROM yourtable WHERE ip='111.111.111.111'")); 
if it returns 1 or more rows then the row exists
__________________
Kenetix:: Achieving more than the ordinary.
http://www.kenetix.net
kenetix is offline   Reply With Quote
Old 02-15-2005, 08:27 PM   PM User | #3
Dylan Leblanc
Regular Coder

 
Join Date: Sep 2002
Location: British Columbia
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Dylan Leblanc is an unknown quantity at this point
This is exactly what the REPLACE command is for http://dev.mysql.com/doc/mysql/en/replace.html
__________________
http://skyscraperpage.com/
Dylan Leblanc is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:20 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.