I have a script that checks an IP address from database, then checks if the IP address is unique or not. If the IP address is not unique, it saves the IP Address to IP_history on database. It's working very slowly, that's why I converted it to mysql stored procedure, but it doesn't run the same. It only runs the 1st procedure. I need it to run 3 procedures in a single page.
Here is my code:
$server = 'localhost'; // MySQL hostname
$username = 'xxx'; // MySQL username
$password = 'xxx'; // MySQL password
$dbname = 'xxx'; // MySQL db name
//$ipvisitor=$_SERVER['REMOTE_ADDR'];
if (isset($_GET['ip']) && $_GET['ip']) {
$ipvisitor = $_GET['ip'];
} else {
$ipvisitor = $_SERVER['REMOTE_ADDR'];
}
$db = new mysqli($server, $username, $password, $dbname);
if ($db->connect_errno) {
echo $db->connect_error;
}
if ($result = $db->query("CALL cekip('$ipvisitor')")) {
$db->error;
}
$dataip = $result->fetch_array();
$hitung = $result->num_rows;
if ($hitung == 0) {
echo "Tidak Ada Dalam Database";
} else {
$cekunik = $db->query("CALL cekhistory('$ipvisitor')");
$unik = $cekunik->num_rows;
if ($unik > 0) {
echo "Sudah Pernah Masuk";
} else {
echo $dataip['country'];
$addhistory = $db->query("CALL addhistory('$ipvisitor')");
}
}
Why is it only running one call? And what is the best approach to fix the issue?