I want some input on what you guys think is the most secure way to connect to a MySQL database using PHP. Currently the way I'm doing it is a utility PHP file that I include in the top of all my other PHP files. The utility PHP file is this:
<?php if(!defined('IN_PHP')){ die("hackerssss"); } $mysql_host = "localhost"; $mysql_user = "root"; $mysql_pass = "root"; $mysql_db = cokertrading; ?>
Any suggestions?
There are two popular ways to connect to a MySQL database using PHP: With PHP's MySQLi Extension. With PHP Data Objects (PDO)
In the control panel's Homepage go the databases section and click the Remote MYSQL option. Then add the Ip address of the Server A and click on add host. Now you can access to the database in Server B while your scripts are running in Server A.
Suggestion: You should probably never be running as root; create another account and give it the 'least' privileges required for your site.
I can believe noone has mentioned MYSQLI and prepared statements yet, you may lock your password and database connection away, but thats ultimately futile if I can simply type ';DROP TABLE users;--
in the login form.
Check http://en.wikipedia.org/wiki/SQL_injection for an idea about what I'm talking about.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With