Advertisement
Guest User

Untitled

a guest
Apr 16th, 2016
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. Database
  2.  
  3. Connect to a fresh MySQL
  4. $serverName = "localhost";
  5. $username = "root";
  6. $password = “";
  7.  
  8. //Create new connection
  9. $conn = new mysqli($serverName, $username, $password);
  10.  
  11. Connect to a MySQL that’s set and ready
  12. $dbName = "StanDB";
  13.  
  14. $conn = new mysqli($serverName, $username, $password, $dbName);
  15.  
  16. Check connection
  17. if($conn->connect_error){
  18. die("Connection failed: ". $conn->connect_error);
  19. }
  20. echo "Connected successfully".NewSpace();
  21.  
  22. Create a database
  23. $sql = "CREATE DATABASE StanDB";
  24. if($conn->query($sql) === TRUE){
  25. echo "Database create successfully";
  26. }else{
  27. echo "Error creating database". $conn->error;
  28. }
  29. Create a table
  30. $sqlCreateTable = "
  31. CREATE TABLE MyGuests(
  32. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  33. firstname VARCHAR(30) NOT NULL,
  34. lastname VARCHAR(30) NOT NULL,
  35. email VARCHAR(50),
  36. reg_date TIMESTAMP
  37. )
  38. ";
  39.  
  40. if($conn->query($sqlCreateTable) === TRUE) {
  41. echo "Table MyGuests created successfully";
  42. }else{Database
  43.  
  44. Connect to a fresh MySQL
  45. $serverName = "localhost";
  46. $username = "root";
  47. $password = “";
  48.  
  49. //Create new connection
  50. $conn = new mysqli($serverName, $username, $password);
  51.  
  52. Connect to a MySQL that’s set and ready
  53. $dbName = "StanDB";
  54.  
  55. $conn = new mysqli($serverName, $username, $password, $dbName);
  56.  
  57. Check connection
  58. if($conn->connect_error){
  59. die("Connection failed: ". $conn->connect_error);
  60. }
  61. echo "Connected successfully".NewSpace();
  62.  
  63. Create a database
  64. $sql = "CREATE DATABASE StanDB";
  65. if($conn->query($sql) === TRUE){
  66. echo "Database create successfully";
  67. }else{
  68. echo "Error creating database". $conn->error;
  69. }
  70. Create a table
  71. $sqlCreateTable = "
  72. CREATE TABLE MyGuests(
  73. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  74. firstname VARCHAR(30) NOT NULL,
  75. lastname VARCHAR(30) NOT NULL,
  76. email VARCHAR(50),
  77. reg_date TIMESTAMP
  78. )
  79. ";
  80.  
  81. if($conn->query($sqlCreateTable) === TRUE) {
  82. echo "Table MyGuests created successfully";
  83. }else{
  84. echo "Error creating table: ". $conn->error;
  85. }
  86. Close connection
  87. $conn->close();
  88.  
  89. echo "Error creating table: ". $conn->error;
  90. }
  91. Close connection
  92. $conn->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement