Connecting to MySQL on 1&1

I’ve created a database on my 1&1 server, I can connect to it through the Plesk control panel with the user I created. I’ve even “reset” the user password to the one I have in my script and can still connect through WebAdmin. However, my PHP script keeps returning the Unable to connect error. I’ve looked over this code time and again and can’t see what it is I am missing. Hopefully someone can show me the error of my ways :smiley:

// Database connection string
$db_server = mysqli_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysqli_error());

or die("Unable to select database: " . mysqli_error());

The file just contains the values for my connection, which I’ve also echoed to the screen from this file to make sure they are properly being chosen and they are good. I’m at a loss as to what it is I am doing wrong. :nono: Any suggestions would be greatly appreciated.

What error code does it show?

That’s one of the things I don’t get, it doesn’t show any error code, just simply my notice - "Unable to connect to MySQL: " (without the quotes, but no error code follows it.

Give this a whirl.

ini_set('display_errors', true);

$config = array(
  'host'    => '',
  'port'    => 3306,
  'user'    => 'AnthonySterling',
  'pass'    => 'MyS3cr37P@5s',
  'schema'  => 'databaseName'

$con = mysqli_connect(

if(false === $con){
  echo 'Error: ' . mysqli_connect_error() ;

echo '<h1>Connected!</h1>';
echo '<p>Info: ', mysqli_get_host_info($con), '</p>' ;


I am also having an issue getting to a 1and1 database.

This is as far as I get with my code.

ini_set('display_errors', true);

1and1 gave me a user of dbo######### and I have verified that the numbers are correct. Same for the database. I am using the correct password.

I get
Notice: Use of undefined constant localhost - assumed ‘localhost’ in /homepages …

and I also get

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /homepages…

I am guessing I should either define localhost, or use something else such as

Found the solution.

ini_set('display_errors', true);
$server= "";

All the information is the same except the $server which is part of the information 1and1 provides.

I managed to find a 1and1 FAQ at which gives the PHP scripts to create a table, add data, etc.

This was a major step for me in my learning. Now, I can start populating the database and learn how to display the information.

You guys ROCK! It was a little of this and that, but I finally figured out my problem. Turns out I wasn’t declaring WHICH database connection to use.

i.e. mysqli_select_db($db_database)
mysqli_select_db($db_server, $db_database)

I also had problems with the format for my server location and username, but I found those because of adding these lines:

ini_set(‘display_errors’, true);

to the top of the script I was currently working on and it would then display (access denied for user blahblahblah) which then pointed me in the direction to look instead of just guessing.

All stuff I should remember from all the books I’ve read that have told me that over and over, but now that I am actually working on a real world app, maybe it will finally start to sink in.

Thanks guys! Hope this helps someone else down the line.