Advertisement
Guest User

Untitled

a guest
May 15th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "med";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. // Check connection
  10. if ($conn->connect_error) {
  11. die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14. // sql to create table USER
  15. $sql_user = "CREATE TABLE User (
  16. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  17. username VARCHAR(30) NOT NULL,
  18. firstname VARCHAR(30) NOT NULL,
  19. lastname VARCHAR(30) NOT NULL,
  20. date_of_birth DATE,
  21. cnp INT(13),
  22. password VARCHAR(30) NOT NULL
  23. )";
  24.  
  25. if ($conn->query($sql_user) === TRUE) {
  26. echo "Table User created successfully";
  27. } else {
  28. echo "Error creating table: " . $conn->error;
  29. }
  30.  
  31. // sql to create table SERVICES
  32. $sql_services = "CREATE TABLE Services (
  33. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  34. name VARCHAR(30) NOT NULL,
  35. price INT(6)
  36. )";
  37.  
  38. if ($conn->query($sql_services) === TRUE) {
  39. echo "Table User created successfully";
  40. } else {
  41. echo "Error creating table: " . $conn->error;
  42. }
  43.  
  44. // sql to create table APPOINTMENT
  45. $sql_appointment = "CREATE TABLE Appointment (
  46. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  47. u_id INT(6) UNSIGNED,
  48. s_id INT(6) UNSIGNED,
  49. first_name VARCHAR(60),
  50. last_name VARCHAR(60),
  51. date DATE,
  52. start INT(3),
  53. end INT(3),
  54. status VARCHAR(60) DEFAULT 'active',
  55. CONSTRAINT fk_a1 FOREIGN KEY (u_id) REFERENCES User(id),
  56. CONSTRAINT fk_a2 FOREIGN KEY (s_id) REFERENCES Services(id)
  57. )";
  58.  
  59. if ($conn->query($sql_appointment) === TRUE) {
  60. echo "Table User created successfully";
  61. } else {
  62. echo "Error creating table: " . $conn->error;
  63. }
  64.  
  65. // sql to create table INVESTIGATION
  66. $sql_investigation = "CREATE TABLE Investigation (
  67. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  68. u_id INT(6) UNSIGNED,
  69. a_id INT(6) UNSIGNED,
  70. investigation VARCHAR(255),
  71. CONSTRAINT fk_i1 FOREIGN KEY (u_id) REFERENCES User(id),
  72. CONSTRAINT fk_i2 FOREIGN KEY (a_id) REFERENCES Appointment(id)
  73. )";
  74.  
  75.  
  76. $insert_sql1 = "INSERT INTO User(username, firstname, lastname, date_of_birth, cnp, password)
  77. VALUES('admin', 'admin', 'admin', '', '', 'admin')";
  78. $execute = mysqli_query($conn, $insert_sql1);
  79.  
  80. $insert_sql2 = "INSERT INTO services(name, price)
  81. VALUES
  82. ('Extractie dentara cu anestezie', '240'),
  83. ('Tratamentul cariei simple', '125'),
  84. ('Reparatie/rebazare proteza', '50'),
  85. ('Reparatie aparat ortodontic', '100')";
  86. $execute = mysqli_query($conn, $insert_sql2);
  87.  
  88.  
  89.  
  90.  
  91. if ($conn->query($sql_investigation) === TRUE) {
  92. echo "Table User created successfully";
  93. } else {
  94. echo "Error creating table: " . $conn->error;
  95. }
  96.  
  97.  
  98. $conn->close();
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement