Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a php file to connect to my database hosted on ipages.com with the following simple code:

<?php

mysql_connect('hostname', 'username', 'password');
?>

When I load this page, I get in return 0. No error message. I previously could not connect to the website using FTP with Filezilla, I had to contact the host to give me access. Is there a similar problem here? I have to access the host to get access to my database?

share|improve this question
up vote 1 down vote accepted

Firstly, you should look to switch to mysqli as the method you are using is being discouraged. The method you should be using is documented here: http://www.php.net/manual/en/mysqli.construct.php

The connection will simply create a connection object to your DB, beyond this it does nothing. You should look at using a block like the one below, which will give you an idea of the status of your connection object:

$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link);

share|improve this answer
    
Its working now! thank you, but still how where I supposed to know that this method was old? – Conrad Nov 23 '12 at 2:20
    
The Php.net manual page has it up top in red ;) – daveh Nov 23 '12 at 3:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .