Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Secure connection to database

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Secure connection to database

Postby legendin » Fri Apr 26, 2013 2:04 am

Hi everyone,

I'm new to PHP and need some advices.

1. I need to etablish a connection to mySQL database (, however, i found out that it's not safe, if the username and password to database is saved in php file. I heard about configuration files - is it safe? What is the best pattern to connect database through php code?


New php-forum User
New php-forum User
Posts: 2
Joined: Fri Apr 26, 2013 1:58 am

Re: Secure connection to database

Postby johnj » Sun Apr 28, 2013 1:55 am

php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Secure connection to database

Postby swarups » Sun Apr 28, 2013 9:39 pm


Yes, it is safe to store db credentials in a different config.php file. But the config.php file should be in a different folder like configs or includes and wherever db connection is required include the config.php file.

You can also use PDO for secure db connection

New php-forum User
New php-forum User
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm

Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.