Php offers multiples ways to connect to a local or remote MySQL database, each requiring a bit of coding knowledge.
PHP's MySQL functions
<?php mysql_connect('localhost','username','password'); mysql_select_db("dbname"); ?>
Where 'localhost' would be your own server (if not remote, case in which you would have to enter the domain or IP). 'username' and 'password' would be for the database that you are connecting to, that is named 'dbname'.
PHP's MySQLi
The mysqli class is an improved method of connection, that is set to be a replacement of the regular functions.
<?php $mysqli = new mysqli("localhost", "username", "password", "dbname"); ?>
PHP's MySQL PDO Classes
Another way to connect to MySQL us by using MySQL's PHP Data Objects (PDO).
<?php $myPDO = new PDO('mysql:host=localhost;dbname=dbname', 'username', 'password'); ?>
And don't forget, for remote connections the port is 3306.
Use PHP to connect to MySQL Print
- php, mysql
- 83
Was this answer helpful?
Related Articles
What happens if I go over my bandwidth limit?
You will get a notification when you've reached 90% of your allocated bandwidth. If you reach the...
How do I add more bandwidth?
There are two ways you can add more bandwidth.1.) You can upgrade your account to add more...
How does DDoS protection work?
We provide DDoS filtering up to 10 Gbps included with all of our VPS plans at all locations. If...
Do you create backups of the VPS?
We do a snapshot backup of every VPS to dedicated backup server. This snapshot backup is for...
How do i set reverse DNS (PTR) on my ip address?
In order to set rDNS on your IP please open a ticket to our support department and we will apply...