I use this SQL query below for my .net licensing system, that licenses users through a back-end api written in PHP.
Now i'm not too smart when it comes to SQL, but if someone could point me in the right direction to optimize the following code, it would greatly help!
CONNECTION PHP:
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'test');
define('DB_USERNAME', 'user');
define('DB_PASSWORD', 'Codwawmw2%');
$odb = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD);
?>
SQL QUERY:
} elseif ($Action == "BackLogin"){
$userID123 = $_GET['uid'];
$hwid = $_GET['hwid'];
$ip = getRealIpAddr();
$pcname = $_GET['pcname'];
$time123 = time();
$GetRows = $odb->query("SELECT * FROM `Account` WHERE uid = '$userID123'");
$row_count = $GetRows->rowCount();
$count = $row_count;
if($count == 0){
$odb->exec("INSERT INTO `Account` (id, uid, cpukey, ip, pcname, online, function, lastlogon) VALUES(NULL,'$userID123','$hwid','$ip','$pcname','0','None','$time123')");
$response = 'Not Banned';
} else {
$response = 'Not Banned';
}
if ($response == "Not Banned")
{
$finaleresponse = "Success";
$odb->exec("UPDATE Account SET `online` = '1', `lastlogon` = '$time123', `ip` = '$ip' WHERE `uid` = '$userID123'");
}
else
{
$finaleresponse = "Error";
}
echo Encrypt($finaleresponse);
}
By the way, the reason I need to optimize the script is that every time its ran by 50+ clients simultaneously it will cause heavy load on the website/server and will literally lag the whole site to the point of no load...
Thanks to anyone who can help :)