无法创建数据库php

f0brbegy  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(303)

我开始创建我自己的接口来与mysql一起使用,尽管我似乎不能用我在底部的代码创建一个数据库。其他的一切都可以工作,我可以回显$obtaindatabase变量,以查看它是否存储了一个值。有什么建议都可以。

<?php
    session_start();

    //define connection
    $conn = new mysqli('localhost', 'over_watch','XXXXXXx','billing');

    //Variables
    $UserEmail = $_SESSION['email'];
    $MysqlUserDataBaseCreate  = $_POST['create_database'];

    //CheckIfUserExists
    $SeeIfUserExist = $conn->prepare("SELECT (email) FROM database_users WHERE email= ?;");
    $SeeIfUserExist->bind_param('s',$UserEmail);
    $SeeIfUserExist->execute();

     $SeeIfUserExist->bind_result($ObtainedEmail);
     $SeeIfUserExist->store_result();
     $SeeIfUserExist->fetch();
     $RowsReturnedFromPreparedStatment = $SeeIfUserExist->num_rows();

    if($RowsReturnedFromPreparedStatment < 1){
      $InsertIntoDatabase = $conn->prepare("INSERT INTO database_users(email,check_if_created) VALUES(?,?);");
      $InsertIntoDatabase->bind_param('ss',$UserEmail,$MysqlUserDataBaseCreate);
      $InsertIntoDatabase->execute();

      $SelectDatabaseToCreate = $conn->prepare(" SELECT (check_if_created) FROM database_users WHERE email = ?;");
      $SelectDatabaseToCreate->bind_param('s', $UserEmail);
      $SelectDatabaseToCreate->execute();

      $SelectDatabaseToCreate->bind_result($ObtainDatabase);
      $SelectDatabaseToCreate->fetch();
      $CreateDatabase = "CREATE DATABASE $ObtainDatabase ;";
      $conn->query($CreateDatabase);

    }else{
      echo 'user permitted to one database';
    }

    ?>
3xiyfsfu

3xiyfsfu1#

你能试试这个密码吗。
有关此错误的详细信息可以在mysql文档中找到。阅读这些细节可以清楚地看到,在同一连接上执行另一条准备好的语句之前,需要完全获取一条准备好的语句执行的结果集。
这是你可以参考的文件

<?php
    session_start();

    //define connection
    $conn = new mysqli('localhost', 'over_watch','XXXXXXx','billing');

    //Variables
    $UserEmail = $_SESSION['email'];
    $MysqlUserDataBaseCreate  = $_POST['create_database'];

    //CheckIfUserExists
    $SeeIfUserExist = $conn->prepare("SELECT (email) FROM database_users WHERE email= ?;");
    $SeeIfUserExist->bind_param('s',$UserEmail);
    $SeeIfUserExist->execute();
    $SeeIfUserExist->store_result();

     $SeeIfUserExist->bind_result($ObtainedEmail);
     $SeeIfUserExist->store_result();
     $SeeIfUserExist->fetch();
     $RowsReturnedFromPreparedStatment = $SeeIfUserExist->num_rows();

    if($RowsReturnedFromPreparedStatment < 1){
      $InsertIntoDatabase = $conn->prepare("INSERT INTO database_users(email,check_if_created) VALUES(?,?);");
      $InsertIntoDatabase->bind_param('ss',$UserEmail,$MysqlUserDataBaseCreate);
      $InsertIntoDatabase->execute();
      $InsertIntoDatabase->store_result();

      $SelectDatabaseToCreate = $conn->prepare(" SELECT (check_if_created) FROM database_users WHERE email = ?;");
      $SelectDatabaseToCreate->bind_param('s', $UserEmail);
      $SelectDatabaseToCreate->execute();
      $SelectDatabaseToCreate->store_result();

      $SelectDatabaseToCreate->bind_result($ObtainDatabase);
      $SelectDatabaseToCreate->fetch();
      $CreateDatabase = "CREATE DATABASE $ObtainDatabase ;";
      $conn->query($CreateDatabase);

    }else{
      echo 'user permitted to one database';
    }

    ?>

相关问题