Last active
February 6, 2020 02:36
-
-
Save anjanesh/1270149 to your computer and use it in GitHub Desktop.
multi-query select via mysqli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mysqli = new mysqli("localhost", "username", "password", "data"); | |
if (mysqli_connect_errno()) | |
die("Connect failed: ".mysqli_connect_error()); | |
$sql1 = "SELECT i1.`Name`, i1.`Branch`, i1.`IFSC`, i1.`Address`, i1.`Contact` | |
FROM `ifsc1` i1 | |
WHERE i1.`Branch` LIKE '%sreekariyam%' OR i1.`Address` LIKE '%sreekariyam%' | |
;"; | |
$sql2 = "SELECT i2.`Name`, i2.`Branch`, i2.`IFSC`, i2.`Address`, i2.`Contact1` | |
FROM `ifsc2` i2 | |
WHERE i2.`Branch` LIKE '%sreekariyam%' OR i2.`Address` LIKE '%sreekariyam%' | |
;"; | |
$sql3 = "SELECT i3.`Name`, i3.`IFSC`, i3.`MICR`, i3.`Address`, i3.`SFMS`, i3.`BSR1`, i3.`BSR2` | |
FROM `ifsc3` i3 | |
WHERE i3.`Address` LIKE '%sreekariyam%' | |
;"; | |
$sql = $sql1.$sql2.$sql3; | |
$sql_num = 1; | |
if ($mysqli->multi_query($sql)) | |
{ | |
do | |
{ | |
if ($result = $mysqli->store_result()) | |
{ | |
while ($row = $result->fetch_assoc()) | |
{ | |
switch ($sql_num) | |
{ | |
case 1: | |
echo $row['Name'].' : '.$row['IFSC'].'<br/>'; | |
break; | |
case 2: | |
echo $row['Name'].' : '.$row['IFSC'].'<br/>'; | |
break; | |
case 3: | |
echo $row['Name'].' : '.$row['IFSC'].'<br/>'; | |
break; | |
} | |
} | |
} | |
if ($mysqli->more_results()) | |
echo '<hr/>'; | |
$sql_num++; | |
} while ($mysqli->next_result()); | |
} | |
else | |
{ | |
echo "Error : ".$mysqli->errno." : ".$mysqli->error; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment