Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. <?php
  2. echo "
  3. <!doctype html>
  4. <html lang = \"en\">
  5. <head>
  6. <meta charset = \"UTF-8\">
  7. <title>Insert Into Pets</title>
  8. </head>
  9. <body>";
  10. function OpenDbObjectionCreateDatabase()
  11. {
  12. $Host = "localhost";
  13. $UserName = "root";
  14. $Password = "mysql";
  15.  
  16. $DbObj = new mysqli($Host, $UserName, $Password);
  17. if ($DbObj->DbObject_errno == 0)
  18. echo "<p>DbObjection open</p>" ;
  19. else
  20. {
  21. echo "<p>DbObjection failed. Error #: " . $DbObj->DbObject_errno .
  22. " Error: " . $DbObj->DbObject_error . "</p>";
  23. exit;
  24. }
  25.  
  26. $dbName = "asst2";
  27. $sql = "
  28. DROP DATABASE IF EXIST $dbName
  29. CREATE DATABASE $dbName
  30. ";
  31. if ($DbObj->query($sql) === TRUE) {
  32. echo "Database created successfully";
  33. } else {
  34. echo "Error creating database: " . $DbObj->error;
  35. exit;
  36. }
  37. $DbObj->select_db($dbName);
  38. }
  39.  
  40. function DropTable($tableName)
  41. {
  42. $stmt = $DbObj->prepare("Drop table If Exists $TableName");
  43. $stmt->execute();
  44. $stmt->close();
  45. }
  46.  
  47.  
  48. function CreatePatientsTable()
  49. {
  50. $IDNum = "IDNum INT";
  51. $HCN = "HCN VARCHAR(20)";
  52. $PatientName = "PatientName VARCHAR(20)";
  53. $BirthDate = "BirthDate DATE(20)";
  54. $SQLStatement = "Create Table PatientsTable($IDNum, $HCN, $PatientName,
  55. $BirthDate)";
  56.  
  57. $stmt = $DbObj->prepare($SQLStatement);
  58. if ($stmt == false)
  59. { echo "Prepare failed on query $SQLStatement";
  60. exit;
  61. }
  62.  
  63. $CreateResult = $stmt->execute();
  64. if ($CreateResult)
  65. echo "$TableName table created.";
  66. else
  67. echo "Can't create table $TableName." .
  68. $stmt->error;
  69. $stmt->close();
  70. }
  71.  
  72. function CreateApptTable()
  73. {
  74. $ApptIDNum = "IDNum INT";
  75. $ApptDate = "ApptDate DATE";
  76. $ApptTime = "ApptTime TIME";
  77. $SQLStatement = "Create Table ApptTable($IDNum, $ApptDate, $ApptTime)";
  78. $stmt = $DbObj->prepare($SQLStatement);
  79.  
  80. if ($stmt == false)
  81. { echo "Prepare failed on query $SQLStatement";
  82. exit;
  83. }
  84.  
  85. $CreateResult = $stmt->execute();
  86. if ($CreateResult)
  87. echo "$TableName table created.";
  88. else
  89. echo "Can't create table $TableName." .
  90. $stmt->error;
  91. $stmt->close();
  92. }
  93.  
  94. function InsertIntoPatientsTable($IDNum,$HCN, $PatientName, $BirthDate)
  95. {
  96. $SQLStatement = "Insert Into PatientsTable (IDNum, HCN, PatientName, $BirthDate)
  97. Values (?, ?, ?, ?)";
  98. $stmt = $DbObj->prepare($query);
  99.  
  100. if ($stmt == false)
  101. { echo "Prepare failed on query $SQLStatement" . $stmt->errno .
  102. ") " . $stmt->error;;
  103. exit;
  104. }
  105.  
  106. $BindSuccess = $stmt->bind_param($IDNum, $HCN, $PatientName, $BirthDate);
  107.  
  108. if (!$BindSuccess)
  109. echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
  110.  
  111. $success = $stmt->execute();
  112.  
  113. if ($success)
  114. echo "Insert in to Patients table succeeded";
  115. else
  116. echo "Insert in to Patients table failed";
  117.  
  118. $stmt->close();
  119. }
  120.  
  121. function InsertIntoApptTable($ApptIDNum,$ApptDate, $ApptTime)
  122. {
  123. $SQLStatement = "Insert Into ApptTable (IDNum, ApptDate, ApptTime) Values
  124. (?, ?, ?)";
  125. $stmt = $DbObj->prepare($query);
  126.  
  127. if ($stmt == false)
  128. { echo "Prepare failed on query $SQLStatement" . $stmt->errno .
  129. ") " . $stmt->error;;
  130. exit;
  131. }
  132.  
  133. $BindSuccess = $stmt->bind_param($ApptIDNum, $ApptDate, $ApptTime,);
  134. if (!$BindSuccess)
  135. echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
  136.  
  137. $success = $stmt->execute();
  138.  
  139. if ($success)
  140. echo "Insert in to Appts table succeeded";
  141. else
  142. echo "Insert in to Appts table failed";
  143.  
  144. $stmt->close();
  145. }
  146.  
  147. function ShowAll()
  148. {
  149.  
  150. $query = "SELECT PatientsTable.IDNum, PatientsTable.PatientName, PatientsTable.HCN,
  151. PatientsTable.BirthDate, ApptTable.ApptDate, ApptTable.ApptTime
  152. FROM PatientsTable INNER JOIN ApptTable
  153. ON PatientsTable.IDNum = ApptTable.IDNum";
  154. $stmt = $DbObj->prepare($query);
  155.  
  156. $stmt->bind_result($IDNum, $PatientName, $HCN, $BirthDate, $ApptDate, $ApptTime);
  157. $stmt->execute();
  158.  
  159. <table> <tr> <th>ID number</th> <th>name</th> <th>health card number</th>
  160. <th>birdhdate</th> <th>appointment date</th> <th>appointment time</th></tr>
  161. while ($stmt->fetch())
  162. echo "<tr><th>$IDNum</th> <th>$PatientName</th> <th>$HCN</th> <th>$BirthDate</th>
  163. <th>$ApptDate</th> <th>$ApptTime</th></tr>";
  164. </table>
  165. $stmt->close();
  166. }
  167.  
  168. function UpdateData($IDNum, $HCN, $PatientName, $BirthDate)
  169. {
  170. $query = "UPDATE PatientsTable SET HCN= ?, PatientName = ?, BirthDate = ?
  171. WHERE IDNum = ?";
  172. $stmt = $DbObj->prepare($query);
  173. $BindSuccess = $stmt->bind_param("dss", $HCN, $PatientName, $BirthDate);
  174.  
  175. if (!$BindSuccess)
  176. echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
  177. $success = $stmt->execute();
  178. if ($success)
  179. echo "<p>Update succeeded</p>";
  180. else
  181. echo "<p>Update failed</p>";
  182. $stmt->close();
  183. }
  184. mysqli_close($DbObj);
  185. echo "</body>\n";
  186. echo "</html>\n";
  187.  
  188.  
  189.  
  190. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement