I am trying to make a code that checks data from multiple databases having the similar table. so I made an array of databases and table in which I want to check the data is present or not as given below
$DatabaseDetails=array(
array('DatabaseName'=>'database1','TableName'=>'table1'),
array('DatabaseName'=>'database2','TableName'=>'table2'),
array('DatabaseName'=>'database3','TableName'=>'table3')
);
Then I tried some code that if it does not find the data in 1st database it move to second one and so on until it find the data else "print no data in database" but i didn't get the expected result. I am new to php so have not much idea. So any help is highly appreciated and Thank you in advance. My code is given below.
<?php
class FindData{
public $DatabaseDetails=array(
array('DatabaseName'=>'database1','TableName'=>'table1'),
array('DatabaseName'=>'database2','TableName'=>'table2'),
array('DatabaseName'=>'database3','TableName'=>'table3')
);
public function SqlData(){
$i=0;
$count=count($this->DatabaseDetails);
$email="[email protected]";
$con=mysqli_connect('localhost','root','',$this->DatabaseDetails[$i]['DatabaseName']);
$sql="select * from ".$this->DatabaseDetails[$i]['TableName']." where email='".$email."'"
;
$run=$this->Data(mysqli_query($con,$sql));
if(strpos($run,'No data')!==false){
$i+=1;
}else{
echo $run;
}
}
public function Data($run){
if($run){
$num=mysqli_num_rows($run);
if($num>=1){
return "Data is in presented";
}else{
return "No data";
}
}
}
}
$obj=new FindData();
$obj->SqlData();
?>