February 27, 2013

PHP Connection string

Question by Richard Griffiths

Im having a few difficulties when connecting to a database using PHP. Im using the following code:

$db=mysql_connect ("HOST", "USER", "PASS") or die ('I cannot connect to the database because: ' . mysql_error());

and it works fine when connecting to a host using phpmyadmin. But my clients host is using something called mylittletools.net and for some reason the connection string will not access the database.

Its been racking my brain for days, I would really appreciate it if anyone could shed any light on this for me.

Answer by Starx

Your syntax is correct, unless it is the variable problems as mentioned in comments the only explanations are that

  • your server does not have MySQL server
  • or PHP’s MySQL driver is not working or not enabled.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!