<?php session_start();
error_reporting(E_ALL & ~E_NOTICE); 
ob_start(); 
$db_host		=$_REQUEST['db_host'];
$db_name	=$_REQUEST['db_name'];
$db_username	=$_REQUEST['db_username'];
$db_password	=$_REQUEST['db_password'];

//print_r($_REQUEST);


  try {
    $conn = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset=utf8',$db_username,$db_password);
        $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
        $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
        $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $conn->setAttribute( PDO::MYSQL_ATTR_INIT_COMMAND , "SET NAMES utf8" );
        //$conn->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'");
        $conn->query('SET NAMES utf8');


       $sql="SHOW TABLES FROM ".$db_name."";
$myquery=$conn->query($sql);
$mydara=$myquery->fetchAll();
$rowfounds=$myquery->rowCount();
echo $rowfounds;
if($rowfounds=='28'){
    echo 'success';
}
else
    {
       throw new PDOException();
    }
        if($conn){
            
            $myfile = fopen("./../../config/coredb.php", "w") or die("Unable to open file!");
            
$txt = "<?php \$domain=\$_SERVER['HTTP_HOST'];
		if(\$domain=='localhost'){ 	
		define('DB_HOST', '".$db_host."');
		define('DB_USER', '".$db_username."');
		define('DB_PASS', '".$db_password."');
		define('DB_NAME', '".$db_name."');
		}else{	
		define('DB_HOST', '".$db_host."');
		define('DB_USER', '".$db_username."');
		define('DB_PASS', '".$db_password."');
		define('DB_NAME', '".$db_name."');
		}   
		?>";
fwrite($myfile, $txt);

fclose($myfile);
 

//fclose($myadmin);
$_SESSION["created"] = 'created_pro' ;
    header("location:./../credentials.php");
         
        }
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    	$_SESSION["failed"] ='43' ;
     header("location:./../sql-connection.php");
    }
    
    ?>