There are so many mistakes in the code, it also uses very dangerous and
obsolete techniques. Some functions you're using even aren't a part of the
lastest versions of the PHP language anymore. Why don't you learn from our free
database course? Just visit https://www.ict.social/php/database and see how to do this
correctly.
As you can see there is almost no way to work with databases in PHP without
objects. However, what you can do is use a wrapper. Basically, someone wrapped
the object-oriented functions in the PDO driver for you in a way that you can
understand them. In other words, you will be able to use them even if you have
no clue what an object actually is. This is the approach we are going to use in
this course.
PHP functions are complicated inside as well and you use them. Just use it as
a part of the language. There is currently no way to work with databases in PHP
efficiently without a wrapper.