Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. /***
  3.  * make_db.php
  4.  * automatically create a database for administrator login
  5.  ***/
  6.  
  7. $mysql_host="localhost";
  8. $mysql_user="root";
  9. $mysql_pass="blah";
  10.  
  11. $database = "punkcms";  // database to make
  12.  
  13. // connect
  14. $connection = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
  15.  
  16. // check the connection
  17. if (!$connection) {
  18.         die('Could not connect: ' . mysql_error());
  19. }
  20.  
  21. // if we cant select our database, we need to create it
  22. if (!mysql_select_db($database, $connection)) {
  23.  
  24.         if (!mysql_query("CREATE DATABASE " . $database, $connection)) {
  25.                 die('Error creating database: ' . mysql_error());
  26.         }
  27.  
  28.         $table = "Administrator";
  29.  
  30.         // create the table
  31.         mysql_select_db($database, $connection);
  32.         mysql_query("CREATE TABLE " . $table .
  33.                         "(username varchar(15), password varchar(15))" , $connection
  34.         );
  35.  
  36.         mysql_query("INSERT INTO " . $table .
  37.                         "(username, password) VALUES ('admin', 'thisismypassword')" , $connection
  38.         );
  39.  
  40. } else {
  41.         echo "database exists!";
  42. }
  43.  
  44.  
  45.  
  46.  
  47. // close connection
  48. mysql_close($connection);
  49.  
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement