I'm trying to learn PHP and MySql. I'm using Phpmyadmin on a virtual hosting plan. I've created a test database and added a few records. Now I'm trying to create a php document to display the records but I'm having trouble connecting to the database. The code I've used is a s follows

<?PHP $db = @mysql_connect("localhost", "root ", "password");
mysql_select_db("mydb",$db);

I've substituted "localhost" for the url of the virtual hosting company and "root " for my username. But when I call up the php page I get an error like "Warning: Supplied argument is not a valid MySQL-Link resource in /home/sites/site101/web/test.php on line 2". Do I need to enter the actual full URL to my database and if so how do I know what that is?

I am a complete PHP and MySql beginner so I might have totally the wrong Idea here?? 😕

    Hi there,

    Mind you Im new to PHP myself, but as I understand it you will have to enter the url of host where your MySQL db lives. You said a hosting company? you will need to give a call to your webmaster or better yet the network admin to get the url, nah scratch that MySQL listens on it own port so if you know the IP address of the host where your MySQL db lives use that instead of the URL...that should do it.

    If your MySQL db is living on your local machine use 127.0.0.1 this equates to the same as "localhost".

    Kenderized

      using mysql_error() might give you a more detailed report, are you already using that?

      <?PHP
      $db = @mysql_connect("localhost", "root ", "password");
      mysql_select_db("mydb",$db) or die(mysql_error());
      ?>

      incase you aren't.

        Thanks!! I put the hosting companies IP address in place of "localhost" and I added "or die(mysql_error())" Now I get this error "Warning: Supplied argument is not a valid MySQL-Link resource in /home/sites/site101/web/ope.php on line 2 Access denied for user: 'andy@www.xyz.com' (Using password: YES)"

        Do you think the problem is something I'm doing wrong or a problem/setting at the hosting company?

          okay your script seems to be okay, it's a problem with MySQL granting authorization to the user. Is the user both created and added to the database?

            The admin guy at the hosting company created one databae for me and gave me a username and password.

            But when I log into my phpmyadmin page I get an error saying "Warning: You haven't enabled magic_quotes_gpc in your PHP configuration. PhpMyAdmin needs this to work properly. Please have a look at the configuration section of the PHP manual for information on how to enable it."

            I was able to creat a database OK though, would this error be anything to do with why I can't bring my data into a page?

              Thanks for the link, I've forwarded it to the hosting company.

              I've substitued "localhost" for the IP address of the hosting company but still doesn't work.

                Write a Reply...