PHP CRUD

PHP CRUD

WHAT IS CRUD?
CRUD stands for create, read, update and delete.  Each term is very self-explanatory.

Create
The word create inserts fresh data into a database; hence the word create.

Read
The term read refers to reading data from a database. No data in the database is altered in any way. However, you can output the data any way you see fit.

Note: when you work with filrs from other programmers you may find code is written, you may find variables, arrays and other programming methodologies varied from your own. Often, the code looks more confusing but it does the same thing.

Below is an example of extracting data from the database. The data shown represents all first names in the chosen database table.

// Obscure
$command = "select * from table_sort ORDER BY date DESC";
$result = mysqli_query($db. $command);
if(mysqli_num_rows($result) != 0){
while($row = mysqli_fetch_assoc($result)){
$var1[$row['first']] = $row['firstname'];
$var2[$row['first']] =  $row['lastname'];

echo $var1[$row['first']];

}
}

echo "<br/><br/>Simple:<br/><br/>";
//Simple
$command = "select * from table_sort ORDER BY date DESC";
$result = mysqli_query($db, $command);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$var1 = $row['firstname'];
$var2 =  $row['lastname'];

echo $var1;

}
}

Update
Update takes place when you alter data which already exists. For example, you may change a blog entry and thus it gets updated.

Delete
The delete term represents the removal of specific row(s) of data from a database. For example, you may want to delete an old blog entry.