Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.