Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo "
- <!doctype html>
- <html lang = \"en\">
- <head>
- <meta charset = \"UTF-8\">
- <title>Insert Into Pets</title>
- </head>
- <body>";
- function OpenDbObjectionCreateDatabase()
- {
- $Host = "localhost";
- $UserName = "root";
- $Password = "mysql";
- $DbObj = new mysqli($Host, $UserName, $Password);
- if ($DbObj->DbObject_errno == 0)
- echo "<p>DbObjection open</p>" ;
- else
- {
- echo "<p>DbObjection failed. Error #: " . $DbObj->DbObject_errno .
- " Error: " . $DbObj->DbObject_error . "</p>";
- exit;
- }
- $dbName = "asst2";
- $sql = "
- DROP DATABASE IF EXIST $dbName
- CREATE DATABASE $dbName
- ";
- if ($DbObj->query($sql) === TRUE) {
- echo "Database created successfully";
- } else {
- echo "Error creating database: " . $DbObj->error;
- exit;
- }
- $DbObj->select_db($dbName);
- }
- function DropTable($tableName)
- {
- $stmt = $DbObj->prepare("Drop table If Exists $TableName");
- $stmt->execute();
- $stmt->close();
- }
- function CreatePatientsTable()
- {
- $IDNum = "IDNum INT";
- $HCN = "HCN VARCHAR(20)";
- $PatientName = "PatientName VARCHAR(20)";
- $BirthDate = "BirthDate DATE(20)";
- $SQLStatement = "Create Table PatientsTable($IDNum, $HCN, $PatientName,
- $BirthDate)";
- $stmt = $DbObj->prepare($SQLStatement);
- if ($stmt == false)
- { echo "Prepare failed on query $SQLStatement";
- exit;
- }
- $CreateResult = $stmt->execute();
- if ($CreateResult)
- echo "$TableName table created.";
- else
- echo "Can't create table $TableName." .
- $stmt->error;
- $stmt->close();
- }
- function CreateApptTable()
- {
- $ApptIDNum = "IDNum INT";
- $ApptDate = "ApptDate DATE";
- $ApptTime = "ApptTime TIME";
- $SQLStatement = "Create Table ApptTable($IDNum, $ApptDate, $ApptTime)";
- $stmt = $DbObj->prepare($SQLStatement);
- if ($stmt == false)
- { echo "Prepare failed on query $SQLStatement";
- exit;
- }
- $CreateResult = $stmt->execute();
- if ($CreateResult)
- echo "$TableName table created.";
- else
- echo "Can't create table $TableName." .
- $stmt->error;
- $stmt->close();
- }
- function InsertIntoPatientsTable($IDNum,$HCN, $PatientName, $BirthDate)
- {
- $SQLStatement = "Insert Into PatientsTable (IDNum, HCN, PatientName, $BirthDate)
- Values (?, ?, ?, ?)";
- $stmt = $DbObj->prepare($query);
- if ($stmt == false)
- { echo "Prepare failed on query $SQLStatement" . $stmt->errno .
- ") " . $stmt->error;;
- exit;
- }
- $BindSuccess = $stmt->bind_param($IDNum, $HCN, $PatientName, $BirthDate);
- if (!$BindSuccess)
- echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
- $success = $stmt->execute();
- if ($success)
- echo "Insert in to Patients table succeeded";
- else
- echo "Insert in to Patients table failed";
- $stmt->close();
- }
- function InsertIntoApptTable($ApptIDNum,$ApptDate, $ApptTime)
- {
- $SQLStatement = "Insert Into ApptTable (IDNum, ApptDate, ApptTime) Values
- (?, ?, ?)";
- $stmt = $DbObj->prepare($query);
- if ($stmt == false)
- { echo "Prepare failed on query $SQLStatement" . $stmt->errno .
- ") " . $stmt->error;;
- exit;
- }
- $BindSuccess = $stmt->bind_param($ApptIDNum, $ApptDate, $ApptTime,);
- if (!$BindSuccess)
- echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
- $success = $stmt->execute();
- if ($success)
- echo "Insert in to Appts table succeeded";
- else
- echo "Insert in to Appts table failed";
- $stmt->close();
- }
- function ShowAll()
- {
- $query = "SELECT PatientsTable.IDNum, PatientsTable.PatientName, PatientsTable.HCN,
- PatientsTable.BirthDate, ApptTable.ApptDate, ApptTable.ApptTime
- FROM PatientsTable INNER JOIN ApptTable
- ON PatientsTable.IDNum = ApptTable.IDNum";
- $stmt = $DbObj->prepare($query);
- $stmt->bind_result($IDNum, $PatientName, $HCN, $BirthDate, $ApptDate, $ApptTime);
- $stmt->execute();
- <table> <tr> <th>ID number</th> <th>name</th> <th>health card number</th>
- <th>birdhdate</th> <th>appointment date</th> <th>appointment time</th></tr>
- while ($stmt->fetch())
- echo "<tr><th>$IDNum</th> <th>$PatientName</th> <th>$HCN</th> <th>$BirthDate</th>
- <th>$ApptDate</th> <th>$ApptTime</th></tr>";
- </table>
- $stmt->close();
- }
- function UpdateData($IDNum, $HCN, $PatientName, $BirthDate)
- {
- $query = "UPDATE PatientsTable SET HCN= ?, PatientName = ?, BirthDate = ?
- WHERE IDNum = ?";
- $stmt = $DbObj->prepare($query);
- $BindSuccess = $stmt->bind_param("dss", $HCN, $PatientName, $BirthDate);
- if (!$BindSuccess)
- echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
- $success = $stmt->execute();
- if ($success)
- echo "<p>Update succeeded</p>";
- else
- echo "<p>Update failed</p>";
- $stmt->close();
- }
- mysqli_close($DbObj);
- echo "</body>\n";
- echo "</html>\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement