Advertisement
Guest User

Untitled

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