Cannot connect to mysql. Not sure if this info is right.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
groog
Forum Newbie
Posts: 15
Joined: Wed Jun 18, 2008 11:48 am

Cannot connect to mysql. Not sure if this info is right.

Post by groog »

I'm having trouble connecting to the database. Is my Host and User right? The PHPMyAdmin says-
# Protocol version: 10
# Server: myhosting247.com (Localhost via UNIX socket)
# User: groog_admin@localhost
So my code is-

Code: Select all

 
<html>
<body>
<?php
 
$host = 'myhosting247.com';
$user = 'groog_admin@localhost';
$pass = 'THIS IS NOT FOR YOU';
 
mysql_connect($host, $user, $pass) or die('Error connecting to MySQL!');
 
?>
This is a test
</body>
</html>
 
Is this right? I keep getting the error that it won't connect.
CodeC6
Forum Newbie
Posts: 1
Joined: Wed Jun 25, 2008 11:16 am

Re: Cannot connect to mysql. Not sure if this info is right.

Post by CodeC6 »

Depends on how you are using it.
In that particular page, you have no code calling it to connect.

Your need to ensure you have a database created.
Are you positive your host isn't localhost? it appears to be so from phpmyadmin.
Username appears ok.

For instance this is my connect script:

Code: Select all

<?php
 
/**
 * DB CONNECT Script For Project:
 * @copyright 2008
 */
 
    // form submitted
    // set server access variables
    $dbhost = 'localhost';
    $dbuser = 'groog_admin@localhost';
    $dbpass = 'THIS IS NOT FOR YOU';
    $db = 'somedb';
// Open Connection
    $connect= mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
    mysql_select_db($db);
?>

and this is how I call it from within a page:

Code: Select all

<?php
if(!file_exists('db_scripts/_config.inc.php')) die('Fatal Error.');
require_once('db_scripts/_config.inc.php');
 
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
 
$sql = "Select * from `user` (`firstname`, `lastname`) VALUES
('$_POST[firstname]','$_POST[lastname]')";
$result = @mysql_query($sql);
 
 
if (!mysql_query($sql,$connect))
  {
  die(mysql_error());
  } 
?>
<html>
<body>
          <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <table class="adding"> 
    <tr>
  <th colspan="2"> Create User Account</th>
    </tr>
    <tr>      
      <td>
          <small>First Name:</small><input type="text" name="firstname" value="<?php if (isset($_POST['firstname'])) echo $_POST['firstname']; ?>" size="25" maxlength="20" /></td></tr>
     <tr>   
  <td>          <small>Last Name:</small><input type="text" name="lastname" value="<?php if (isset($_POST['lastname'])) echo $_POST['lastname']; ?>" size="25" maxlength="20" /></td>
  </tr>
  <tr><th colspan="2">
           <input type="submit" name="save" value="Save" /></th></tr>   
    </table>
          <input type="hidden" name="submitted" value="TRUE" />
                
            </form>
</body>
</html>
<?
echo "user account exists";
?>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Cannot connect to mysql. Not sure if this info is right.

Post by califdon »

Your problem is probably that you are assuming that the MySQL server, user and password is the same as your hosting service server, user and password. It almost never is. Talk to your hosting service to clarify this.
groog
Forum Newbie
Posts: 15
Joined: Wed Jun 18, 2008 11:48 am

Re: Cannot connect to mysql. Not sure if this info is right.

Post by groog »

I did what you said. But now when I visit the page the network "timed out". And it does it only when the host is localhost because when I switch it back to what I had before the page comes up (but still with the mysql error).
Network Timeout

The server at luminaryhelp.co.nr is taking too long to respond

The requested site did not respond to a connection request and the browser has stopped waiting for a reply.

* Could the server be experiencing high demand or a temporary outage? Try again later.
* Are you unable to browse other sites? Check the computer's network connection.
* Is your computer or network protected by a firewall or proxy? Incorrect settings can interfere with Web browsing.
* Still having trouble? Consult your network administrator or Internet provider for assistance.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Cannot connect to mysql. Not sure if this info is right.

Post by califdon »

groog wrote:I did what you said. But now when I visit the page the network "timed out". And it does it only when the host is localhost because when I switch it back to what I had before the page comes up (but still with the mysql error).
Is this database hosted at a commercial hosting service? If so, you have to understand that "localhost" means THIS COMPUTER, and no hosting service would configure their MySQL servers to run that way. Have you spoken to your hosting service tech support? They are the ones you should be talking to, not here on a forum where we have no way to know the details of your hosting service.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Cannot connect to mysql. Not sure if this info is right.

Post by Eran »

califdon wrote:Is this database hosted at a commercial hosting service? If so, you have to understand that "localhost" means THIS COMPUTER, and no hosting service would configure their MySQL servers to run that way.
Actually that is incorrect. As the MySQL server is usually a service on the actual hosting server, localhost is commonly used. In all the hosting providers I have used till now, that was the case.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Cannot connect to mysql. Not sure if this info is right.

Post by califdon »

pytrin wrote:
califdon wrote:Is this database hosted at a commercial hosting service? If so, you have to understand that "localhost" means THIS COMPUTER, and no hosting service would configure their MySQL servers to run that way.
Actually that is incorrect. As the MySQL server is usually a service on the actual hosting server, localhost is commonly used. In all the hosting providers I have used till now, that was the case.
Oh, really? That surprises me, since my experience has been the opposite, but I yield to the facts when they are presented. I have had experience with only a handful of hosting services, but all of them used dedicated servers that were in a different domain than their web servers.

In any case, I think this person needs to be talking to their hosting service tech support, who can surely straighten him out in a matter of minutes.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Cannot connect to mysql. Not sure if this info is right.

Post by Ollie Saunders »

Yeah I would agree with pytrin.

Try:

$host = 'localhost';
$user = 'groog_admin';
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Cannot connect to mysql. Not sure if this info is right.

Post by Bill H »

Don't know if "groog" has solved his problem or not, but I'd agree with Ollie that "localhost" is probably the right host and the the "@localhost" does not belong in the username. Virtually all of the hosting services I've been on have used "localhost" and more often than not the logon username will be a compound of the site username and the database username joined by an underscore.

I certainly agree with califdon that groog should be talking to his hosting service tech support, because we are merely guessing while they will actually know. It may be the groog has been getting no help from that source and has come here in desperation.
Post Reply