Learn about important database security methods in PHP and how to make it secure and unbreakable against hackers today.

We all know that security is a top priority everywhere.

No matter if you run a small business, have patient information, or have a personal computer at home, we all have to guard our data somehow.

Even the government has procedures to follow in order to avoid classified information to be leaked or hacked by foreign enemies.  It’s imperative to have data locked safely.  You want to avoid any vulnerabilities at all costs.


Articles to Help you Get Successful

The Single Most Effective Way to Master CSS Grid

Bookew vs. Planyo: Which one is the best booking system?

5 Ways to Grow Your Business

5 Benefits of Having a Website for a Small Business

[optin-cat id=5281]


But the question is do you have your code secure?

I want to explain some database security methods you can take to make your database a secure fortress.

Mostly all these database security methods will be functions in your PHP code to make it harder for people to break in.

Lets dive in further.


Steps to unbreakable database security methods:


1.Making your PHP secure – database security methods


  • Put parameters into variables (constants)
  • Convert using strtoupper () function and create a foreach() loop
  • Create an array

Some really cool reads: The easiest and best way to connecting MySQL database using PHP


db connection


2.Preventing SQL injection database security methods


  • Escape strings to clean up and to avoid users deleting your database
  • Example:
  • $username = mysqli_real_escape_string($connection,$password);
  • $password = mysqli_real_escape_string($connection, $password);


sql avoid injection


Some really cool reads: My journey to mastering PHP programming: The easy and best way to PHPMyAdmin creating tables and inserting data



3.Password encryption database security methods


To prevent hackers from knowing usernames and passwords, we want to encrypt them.  We need to do somethings first in our database.  We are going to change the values in our database to make it longer.

  • Change the length or values to 100 or 200

users1 table columns



  • Use the $hashFormat = “$2y$10$”; (This is the blowfish method)
  • Use $salt = “iusesomecrazystrings22”; (this takes in 22 characters)
  • You can see and learn about these more in depth at php.net
  • Another resource I want to point out is about password hash at the documentation for php, which is excellent reference explaining about blowfish and salt and hash (See php password_hash)
  • So when you type in a password this will generate a different password characters, thus encrypting the password so it makes it impossible for hackers to break in with their hacker software



sql avoid injection


Final thoughts

There’s also other hash functions you can use that creates even longer password strings and it’s excellent.  However, this is the one I learned so far, but if I get to use other functions in the future I will probably refer to the php documentation for help again.

This was a great experience learning about database security methods in php.  It was also wonderful passing this information to everyone in the community.

Security is very important against keeping the bad guys out and I highly recommend to keep your usernames and passwords secure in your applications.  It would be a devastating blow if anything would be lost.  We don’t want your users to be compromised in anyway, especially if there’s financial information,  so be safe everyone.

Until next time, be safe!


Need to get in touch? Contact me here