Any idea why I can't connect to mysql db?

When I try to connect to my Godaddy Linux Shared Hosting account database, I get the following message:

Fatal error: Call to undefined function: mysqli_connect() in /home/content/c/c/s/ccsoundsystem/html/CMS/ on line 10

I have successfully installed MODx and ZenCart, so I pretty much understand how to find my hostname, username and password for the GoDaddy databases.

But, now I am trying to learn PHP from the ground up by using some pre-made “for Dummies” code which, so far, has proven to be a whopping piece of shit and I would like to personally strangle everyone involved in its publication.

Here’s the fine code from which gives the above error:

 /*  Function:  Connect_to_db
  *  Desc:      Connects to a MySQL database. The name of
  *             a file containing the database variables
  *             is passed to the function.
  function Connect_to_db($filename)
      $connection = mysqli_connect($host, $user,$passwd) 
               or die ("Couldn't connect to server.");
      $db = mysqli_select_db($connection,$database)
               or die ("Couldn't select database.");
      return $connection;     

It uses a file which looks like this:

<?php $host = ""; $user = "killjanetvalade"; $passwd = "Password123"; $database = "killjanetvalade"; ?>

Yes, Godaddy’s user and database names are the same. This happens automatically when you create a database and it has never been a problem.

The first bunch of code is presumably supposed to call the file to get the information (although, I don’t see where). Now, for some reason the code has an error in line 10.

…and Line 10 is:

$connection = mysqli_connect($host, $user,$passwd) 

And the error, once again, is…
Fatal error: Call to undefined function: mysqli_connect() in /home/content/c/c/s/ccsoundsystem/html/CMS/ on line 10

… “Undefined function?” …

Anyone know what the problem is before I go find and strangle Janet Valade and everyone at the “For Dummies” publication house? (joking, no need to call the police)

Thank you.

A Dummy (for which this “For Dummies” book is clearly not intended!)

Well, the module is not installed for that it seems…

try using mysql_connect…

If that is undefined as well, you do not have mysql module installed on your server…

make a blank page and use

<?php phpinfo(); ?>

in it…

A call to undefined function is just that. The function, in this case, mysqli_connect() has not been defined. It has not been defined because likely the version you are running doesn’t support it, or the module wasn’t loaded. Thus PHP has no idea how to treat the function.

A quick peak over at and also tells me that this is not part of a “Canned Package” install. In fact you would have to specifically install this one at compile time.

I am not sure but I suspect most hosts would probably just stick with the mysql set of functions instead of the mysqli (mysql improved) set of functions as this would likely lead to more “Support” calls for them.

As Acecool suggests, try using just the mysql_connect (_query, _query_db, etc…) without the “Improved” version and see if that solves the issues for you.

Hi, thank you both.

If you are both saying to just remove the “i” at the end of “mysqli” I did try just using “mysql” instead of “mysqli” in that particular place, but I still got an error message. I’m not sure if I did it correctly (I just removed the “i” at the end) because there was some horribly brief and unclear mention of this at the beginning of the book. I just tried it as a crapshoot.

Is removing the “i” what you mean? Or is there more to it?

I also opened the php.ini file on the off chance there might be one of the lines the author said might need uncommenting, but neither line was in the php.ini file.


I uploaded the php you suggested and got the following info:

PHP Version 4.3.11

Configure Command:
‘./configure’ ‘–with-cgi’ ‘–enable-fastcgi’ ‘–with-config-file-path=/web/conf’ ‘–with-gd’ ‘–with-xml’ ‘–with-gettext’ ‘–with-zlib-dir=/usr/src/zlib’ ‘–disable-posix’ ‘–with-jpeg-dir=…/jpeg-6b’ ‘–enable-gd-native-ttf’ ‘–enable-ftp’ ‘–with-freetype-dir=/usr’ ‘–with-freetype’ ‘–with-sybase=/usr/src/freetds’ ‘–with-curl=/usr/bin/curl’ ‘–with-dom’ ‘–enable-calendar’ ‘–enable-soap’ ‘–enable-bcmath’ ‘–with-zip’ ‘–with-openssl’ ‘–with-mcrypt’ '–with-mysql=/usr/local/mysql-5.0’

Virtual Directory Support: disabled

There’s other stuff, but I think that’s probably all you wanted to determine, right?

Does that explain why the mysqli line doesn’t work? :-?

Hooo boy, guess what?!?!

GoDaddy Tech Support said:

The function in question is not enabled on our shared hosting servers. You would need to get a dedicated or virtual dedicated server for that functionality. You can read more about those servers here...

That seems a bit ridiculous since they offer ZenCart and Joomla and everything for the shared hosting servers.

So, anyone know a good, inexpensivle host that would have this enabled?

Okay, Godaddy just got back to me and said mysql_connect() IS supported.

But, if I use mysql_connect(), I get this error message:

Warning: mysql_connect(): Can’t connect to MySQL server on ‘’ (4) in /home/content/c/c/s/ccssoundsystem/html/cms/ on line 10
Couldn’t connect to server.

… which is less informative than the first error message I was getting.

try using localhost as your server - usually it is set up that way unless your database is hosted elsewhere…

No, Godaddy is just a ridulous company.

After several contradictory emails from them, when I finally said: “it is set up exactly how you said, see the files?” I got back the simple response that it is a scripting issue which they don’t support.

But, it can’t be a scripting issue since I’ve run this off my own computer with the same exact script. Only thing that has changed are the database connection variables.

Surprise, surprise, Google turns up a ton of people who are having this same exact problem.

Godaddy, regardless of whether or not they provide decent hosting and support, should have given you the following information:

  • MySQL hostname or IP address
  • MySQL username
  • MySQL password
  • MySQL database name (optional)

The error message you’re receiving means that your hostname or IP address is incorrect (or at least, that on the supplied hostname or IP address, on the port you’ve provided (default = 3307 I think), no MySQL engine is listening).

They also should provide you with the Port number if it’s not on the default of 3307 as well.

With GoDaddy, you can’t use ‘localhost’. You have to use something that looks similar to ‘’.

Also, even if you set allow_url_fopen = on in the php.ini file in your root folder, you can’t use include to bring in a script that includes mysql_connect. for example if your connect file is called connect.php, you use:


This will end in an error. The proper way to do it is:

 include("$_SERVER['DOCUMENT_ROOT'] . '/scripts/connect.php'); 

This is of course if scripts/connect.php is off your root folder.

I’ve been programming for 10 years now and never had the trouble I have had with GoDaddy. I would NOT recommend it to anyone.

If you do have any questions the need answered right away, I can probably help. Just message me.

Sponsor our Newsletter | Privacy Policy | Terms of Service