简体   繁体   中英

I have sort of php code, in this i want to send connection variable ($conn) into another page so that i can create table for database dynamically

<?php    

    $a = $_GET['host'];
    $b = $_GET['username'];
    $c = $_GET['password'];
    $d = $_GET['db_name'];
    define("localhost",$a);
    define("username",$b);
    define("password",$c);
    define("db",$d);
    $conn = mysqli_connect(localhost,username,password);
    if($conn === false){
        die("ERROR: Could not connect. " . mysqli_connect_error());
    }
    // Attempt create database query execution
    $sql = "CREATE DATABASE $d ";
    if(mysqli_query($conn, $sql)){
        echo "Database demo created successfully";
        header("Location:create_table.php");    
    } else{
        echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
    }
    // Close connection
    mysqli_close($conn);

?>

In this i need to send $conn with header to send it to create_table.php page. because i am getting details of connection from user. so i cannot include this file into create_table.php . please help to find out how can i send connection variable into another file.

<?php 

$server= "localhost";
$user= "root";
$pass= "";

$conn= mysqli_connection($server, $user, $pass);

if(!$conn){
echo "Database Connection Install Failed ! ".mysqli_errno() ;
}

else {
echo "Database Connection Establiseh Successfully! ";

}

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM