PHP MySQL: Update, non OOP style

This entry is part 8 of 17 in the series PHP & MySQL

We have used mostly OOP way of making connection to the DB and executing the query string.  Since we are using PHP 5, it is recommended to use OOP method.

By now, you should be able to see how easy it is to execute a query string using PHP.  For this mysql update, we will set up the connection using non OOP way.

Instead of using new mysqli we use mysqli_connect().

$link = mysqli_connect("localhost", "root", "", "allartist");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s", mysqli_connect_error());
} else {
    printf("Connection to DB successful");

$sql = "update artist set year = 1990 where id = 2";

if (mysqli_query($link, $sql) === TRUE) {
    echo "Record updated successfully<br>";
} else {
    echo "Error updating record into table with error no: " . $mysqli->errno;


After updating, you can use Toad to check if the record has been updated correctly.


Series Navigation<< PHP MySQL: Delete
PHP MySQL: Select count >>