SQL Server状态检查器

时间:2012-02-21 22:23:52

标签: php sql status

好吧,我基本上想知道如何在PHP中创建一个SQL变量......这是代码:

/*Database Information*/
$mysql_host = 'localhost';
$mysql_user = 'user';
$mysql_pass = 'pass';
$mysql_db = 'database';

/*Dataase Selecting*/
$ip_var = 'SELECT `ip` FROM `toadd`';
$port_var = 'SELECT `port` FROM `toadd`';
$verified_var = "SELECT `verified` FROM `toadd`";
$change_online_var = "UPDATE servers SET online=1, totalcount=totalcount+1, oncount=oncount+1, `uptime` = (oncount / totalcount * 100) WHERE id=";
$change_offline_var = "UPDATE servers SET online=0, totalcount=totalcount+1, `uptime` = (oncount / totalcount * 100) WHERE id=";
$change_toadd_var = 'INSERT INTO `servers` (`uid`, `uname`, `name`, `ip`, `port`, `version`, `time`, `info`, `ipaddress`, `rs_name`, `rs_pass`) SELECT `uid`, `uname`, `name`, `ip`, `port`, `version`, `time`, `info`, `ipaddress`, `rs_name`, `rs_pass` FROM `toadd` WHERE `id` = ? DELETE FROM `toadd` WHERE `id` = ?'; 

$ip = mysql_query($ip_var);
$port = mysql_query($port_var);
$verified = mysql_query($verified_var);
$change_online = mysql_query($change_online_var);
$change_offline = mysql_query($change_offline_var);

/*SQL Connection*/
@mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die('Error connecting to '.$mysql_db); //Connects to your SQL host
mysql_select_db($mysql_db); //Connects to your database

/*Status Checking*/
$fp = fsockopen($ip, $port, $errno, $errstr, 4);//Takes the IP and Port of the server
    if ($fp) { //If the server is online
        $change_online; //Carry out the Online variable
    } else if(!$fp) { //If the server is offline
        $change_offline; //Carry out the Offline variable
    } else if ($fp && $verified == 1) { //If the server is online, verified and still sitting in the toadd table
        $change_toadd; //Carry out the To Add variable
    } 

/*How to set this application up:
 * Replace all the information under Database Information with your Database Info.
 * Then quick open it up to see if it will work. If not, you did something wrong
 * and you should try to set it up again. If you continue to have problems with
 * the connection, please contact RuneWings317 on MoparScape. If this works, go
 * to your cPanel and set up a "Cron Job". For the command, set the path to this
 * file. You can set the time to whatever you want, but it's suggested that you set
 * it anywhere from 30 minutes to an hour. Make sure it's every day, week, month
 * and year. Goodluck! :D
 */
?></code>
/*Database Information*/ $mysql_host = 'localhost'; $mysql_user = 'user'; $mysql_pass = 'pass'; $mysql_db = 'database'; /*Dataase Selecting*/ $ip_var = 'SELECT `ip` FROM `toadd`'; $port_var = 'SELECT `port` FROM `toadd`'; $verified_var = "SELECT `verified` FROM `toadd`"; $change_online_var = "UPDATE servers SET online=1, totalcount=totalcount+1, oncount=oncount+1, `uptime` = (oncount / totalcount * 100) WHERE id="; $change_offline_var = "UPDATE servers SET online=0, totalcount=totalcount+1, `uptime` = (oncount / totalcount * 100) WHERE id="; $change_toadd_var = 'INSERT INTO `servers` (`uid`, `uname`, `name`, `ip`, `port`, `version`, `time`, `info`, `ipaddress`, `rs_name`, `rs_pass`) SELECT `uid`, `uname`, `name`, `ip`, `port`, `version`, `time`, `info`, `ipaddress`, `rs_name`, `rs_pass` FROM `toadd` WHERE `id` = ? DELETE FROM `toadd` WHERE `id` = ?'; $ip = mysql_query($ip_var); $port = mysql_query($port_var); $verified = mysql_query($verified_var); $change_online = mysql_query($change_online_var); $change_offline = mysql_query($change_offline_var); /*SQL Connection*/ @mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die('Error connecting to '.$mysql_db); //Connects to your SQL host mysql_select_db($mysql_db); //Connects to your database /*Status Checking*/ $fp = fsockopen($ip, $port, $errno, $errstr, 4);//Takes the IP and Port of the server if ($fp) { //If the server is online $change_online; //Carry out the Online variable } else if(!$fp) { //If the server is offline $change_offline; //Carry out the Offline variable } else if ($fp && $verified == 1) { //If the server is online, verified and still sitting in the toadd table $change_toadd; //Carry out the To Add variable } /*How to set this application up: * Replace all the information under Database Information with your Database Info. * Then quick open it up to see if it will work. If not, you did something wrong * and you should try to set it up again. If you continue to have problems with * the connection, please contact RuneWings317 on MoparScape. If this works, go * to your cPanel and set up a "Cron Job". For the command, set the path to this * file. You can set the time to whatever you want, but it's suggested that you set * it anywhere from 30 minutes to an hour. Make sure it's every day, week, month * and year. Goodluck! :D */ ?></code>

And I get this error when I test it on my site:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'reverseg'@'localhost' (using password: NO) in /home/reverseg/public_html/status.php on line 21

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/reverseg/public_html/status.php on line 21

Warning: mysql_query() [function.mysql-query]: Access denied for user 'reverseg'@'localhost' (using password: NO) in /home/reverseg/public_html/status.php on line 22

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/reverseg/public_html/status.php on line 22

Warning: mysql_query() [function.mysql-query]: Access denied for user 'reverseg'@'localhost' (using password: NO) in /home/reverseg/public_html/status.php on line 23

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/reverseg/public_html/status.php on line 23

Warning: mysql_query() [function.mysql-query]: Access denied for user 'reverseg'@'localhost' (using password: NO) in /home/reverseg/public_html/status.php on line 24

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/reverseg/public_html/status.php on line 24

Warning: mysql_query() [function.mysql-query]: Access denied for user 'reverseg'@'localhost' (using password: NO) in /home/reverseg/public_html/status.php on line 25

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/reverseg/public_html/status.php on line 25

Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in /home/reverseg/public_html/status.php on line 32

I removed the database stuff for safety reasons. Also, About this line:

$change_toadd_var = 'INSERT INTO servers (uid, uname, name, ip, port, version, time, info, ipaddress, rs_name, rs_pass) SELECT uid, uname, name, ip, port, version, time, info, ipaddress, rs_name, rs_pass FROM toadd WHERE id = ? DELETE FROM toadd WHERE id = ?';

=?'。我如何才能使它只对已检查的服务器的ID执行操作,我不知道如何... xD

谢谢,非常感谢帮助:)。

0 个答案:

没有答案