簡體   English   中英

我有某種php代碼,在此我想將連接變量($ conn)發送到另一個頁面中,以便我可以動態創建數據庫表

[英]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);

?>

在這種情況下,我需要發送帶有標頭的$ conn,以將其發送到create_table.php頁面。 因為我正在從用戶那里獲得連接的詳細信息。 所以我不能將此文件包含到create_table.php中。 請幫助找出如何將連接變量發送到另一個文件。

<?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! ";

}

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM