简体   繁体   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);

?>

In this i need to send $conn with header to send it to create_table.php page. 在这种情况下,我需要发送带有标头的$ conn,以将其发送到create_table.php页面。 because i am getting details of connection from user. 因为我正在从用户那里获得连接的详细信息。 so i cannot include this file into create_table.php . 所以我不能将此文件包含到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! ";

}

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用 jquery ajax 将变量从一个 php 页面发送到另一个页面 - i want to send variable from one php page to another using jquery ajax 我可以将 php 中的变量发送到另一个页面吗? - Can i send variable in php to anoter page? 如何在另一个 php 文件的函数中使用 $conn - how can I use $conn within a function in another php file 我在 php 中有一个名为 id 的变量。 我想将其用作表名。此代码未在 php myadmin 中创建表 - I have a variable in php called as id. I want to use it as a table name.This code is not creating the table in php myadmin 我可以从PHP $ var中的另一个表创建表吗? - Can I create a table from another table that I have in a $var in PHP 到目前为止,我正在尝试使用PHP在数据库上创建表,但是我设法使用PHP创建了数据库,但无法创建表/表 - I'm trying to create a table on my database using PHP so far i have managed to create a database using PHP but but fail to create table/tables 我想存储一个PHP $ _SESSION变量并在另一页上检索它 - I want to store a php $_SESSION variable and retrieve it on another page 我必须将两个变量 about 和 product 发送到 php 中的另一个页面 - I have to send two variables about and product to another page in php 我应该添加到以下代码中,以便它可以在php变量中保存按钮值,我将在电子邮件中发送它 - What should i add to the following code so that it can save button value onclick in php variable and i will send it in the email 我想将网址发送到另一个PHP函数 - I want to send a url to another php function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM