Hello World!
'; ?>
connect_error) {
die("Step 0: Sorry but the connection failed: " . $objConnection->connect_error);
}
else {
echo "Step 0: Yay, connected successfully let the games begin... ";
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Create of the CRUD process
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "Step 1: Create the table ";
// sql to create table
$strSQL_String = "CREATE TABLE User (intUser_Id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, strUser_Firstname VARCHAR(30) NOT NULL, strUser_Lastname VARCHAR(30) NOT NULL, strUser_Email VARCHAR(50), dteUser_Registered DATETIME )";
if ($objConnection->query($strSQL_String) === TRUE) {
echo "Result 1 : Table User created successfully
" . vbCrLf ;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Insert / Create of the CRUD process
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "Step 2: Create Insert a record into the table ";
// sql to create table
$strSQL_String = "Insert Into User (intUser_Id, strUser_Firstname, strUser_Lastname, strUser_Email, dteUser_Registered )
VALUES ( Null, 'Philip', 'Lacey', 'philiplacey1@gmail.com', NOW() )";
if ($objConnection->query($strSQL_String) === TRUE) {
echo "Result 2 : Record inserted
" . vbCrLf ;
//We repeat the process to create 4 records.
$strSQL_String = "Insert Into User (intUser_Id, strUser_Firstname, strUser_Lastname, strUser_Email, dteUser_Registered ) VALUES ( Null, 'Emma', 'Lacey', 'philiplacey1@gmail.com', NOW() )";
if ($objConnection->query($strSQL_String) === TRUE) {
$strSQL_String = "Insert Into User (intUser_Id, strUser_Firstname, strUser_Lastname, strUser_Email, dteUser_Registered ) VALUES ( Null, 'Hiccup', 'Lacey', 'philiplacey1@gmail.com', NOW() )";
if ($objConnection->query($strSQL_String) === TRUE) {
$strSQL_String = "Insert Into User (intUser_Id, strUser_Firstname, strUser_Lastname, strUser_Email, dteUser_Registered ) VALUES ( Null, 'Gizmo', 'Lacey', 'philiplacey1@gmail.com', NOW() )";
if ($objConnection->query($strSQL_String) === TRUE) {
}
}
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Read of the CRUD process
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//Now we read the contents of the table out to screen.
echo "Step 3: Read the table ";
$strSQL_String = "SELECT * FROM User";
$objResult = $objConnection->query($strSQL_String);
if ($objResult->num_rows > 0) {
// output data of each row
while($objRow = $objResult->fetch_assoc()) {
echo "Result 3: intUser_Id: " . $objRow["intUser_Id"]. " - Name: " . $objRow["strUser_Firstname"]. " " . $objRow["strUser_Lastname"] . " Date [" . $objRow["dteUser_Registered"] . "]
" . vbCrLf;
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Update of the CRUD process
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "Step 4: Update a record in the table ";
$strSQL_String = "Update User Set strUser_Firstname = 'Updated' Where intUser_Id = 2";
if ($objConnection->query($strSQL_String) === TRUE) {
echo "Result 4 : Record updated.
" . vbCrLf;
}
else {
echo "Result 4 : Error updating record: " . $objConnection->error . "
" . vbCrLf;
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Delete of the CRUD process
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "Step 5: Delete a record in the table ";
$strSQL_String = "Delete From User Where intUser_Id = 3";
if ($objConnection->query($strSQL_String) === TRUE) {
echo "Result 5 : Record deleted.
" . vbCrLf;
}
else {
echo "Result 5 : Error deleting record: " . $objConnection->error . "
" . vbCrLf;
}
$strSQL_String = "SELECT * FROM User";
$objResult = $objConnection->query($strSQL_String);
if ($objResult->num_rows > 0) {
// output data of each row
while($objRow = $objResult->fetch_assoc()) {
echo "Result 4 and 5: intUser_Id: " . $objRow["intUser_Id"]. " - Name: " . $objRow["strUser_Firstname"]. " " . $objRow["strUser_Lastname"] . " Date [" . $objRow["dteUser_Registered"] . "]
" . vbCrLf;
}
}
}
else {
echo "Result 3: 0 records
" . vbCrLf ;
}
}
else {
echo "Result 2 : Error inserting record: " . $objConnection->error . "
" . vbCrLf;
}
}
else {
echo "Result 1 : Error creating table: " . $objConnection->error . "
" . vbCrLf;
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Drop / Delete of the CRUD process
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "Step 4: Drop / Delete the table ";
// sql to create table
$strSQL_String = "DROP TABLE User";
if ($objConnection->query($strSQL_String) === TRUE) {
echo "Result 4 : Table User dropped successfully
" . vbCrLf ;
}
else {
echo "Result 4 : Error dropping table: " . $objConnection->error . "
" . vbCrLf;
}
//Tidy up and close the connection
$objConnection->close();
}
?>