Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 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. 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. DropTable($tableName)
  41. {
  42. $stmt = $DbObj->prepare("Drop table If Exists $TableName");
  43. $stmt->execute();
  44. $stmt->close();
  45. }
  46.  
  47.  
  48. CreatePatientsTable()
  49. {
  50. $tableName="PatientsTable"
  51. $IDNum = "IDNum INT";
  52. $HCN = "HCN VARCHAR(20)";
  53. $PatientName = "PatientName VARCHAR(20)";
  54. $BirthDate = "BirthDate DATE(20)";
  55. $SQLStatement = "Create Table $TableName($IDNum, $HCN, $PatientName,
  56. $BirthDate)";
  57.  
  58. $stmt = $DbObj->prepare($SQLStatement);
  59. if ($stmt == false)
  60. { echo "Prepare failed on query $SQLStatement";
  61. exit;
  62. }
  63.  
  64. $CreateResult = $stmt->execute();
  65. if ($CreateResult)
  66. echo "$TableName table created.";
  67. else
  68. echo "Can't create table $TableName." .
  69. $stmt->error;
  70. $stmt->close();
  71. }
  72.  
  73. CreateApptTable()
  74. {
  75. $tableName="ApptTable"
  76. $ApptIDNum = "IDNum INT";
  77. $ApptDate = "ApptDate DATE";
  78. $ApptTime = "ApptTime TIME";
  79. $SQLStatement = "Create Table $TableName($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. 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. 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. 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. <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. </table>
  167. $stmt->close();
  168. }
  169.  
  170. 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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement