Guest User

Untitled

a guest
Apr 21st, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. $user_password = random_str(8);
  2.    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  3.    try {
  4.         $conn = new mysqli($mysql_settings["client"]["host"], $mysql_settings["client"]["user"], $mysql_settings["client"]["password"]);
  5.    } catch (Exception $ex) {
  6.         echo "Service unavailable: ".$ex->getMessage()."\n";;
  7.         exit(1);
  8.    }
  9.    $sql = "CREATE USER `".$result->options["name"]."`@`".$mysql_settings["client"]["host"]."` IDENTIFIED BY '".$user_password."'";
  10.    try {
  11.       if ($conn->query($sql) === TRUE) {
  12.         echo "Successfully created database user: ".$result->options["name"]."`@`".$mysql_settings["client"]["host"]."\n";
  13.         $conn->close();
  14.         exit(0);
  15.       }
  16.       else{
  17.         throw new Exception($conn->error);
  18.       }
  19.    } catch (Exception $ex) {
  20.         echo "Error: ".$ex->getMessage()."\n";;
  21.         $conn->close();
  22.         exit(1);
  23.    }
  24. $conn->close();
  25. }
Add Comment
Please, Sign In to add comment