Dragan Marjanovic Dragan Marjanovic - 1 year ago 75
MySQL Question

Connecting to a mysql Database via PHP?

Ok, Ive been playing around with PHP and databases. Note, Im doing all my work on a webserver hosted by bluehost.
So I went into the cpanel and set up a database called gagalugc_stocks.
I also setup a username (test) and a password (password) and added them to be able to control the databse. Below is my script in an attempt to connect to it, not it is also on the server.

$connect = mysql_connect('localhost','test','password');
if(!$connect){die('Could not reach database!');}
mysql_select_db("gagalugc_stocks", $connect)


NOTE: The problem is that it can never reach the database.

Answer Source

Didn't check for port when adding database make sure to specify host and port

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download