Page 1 of 1
Cannot connect to mysql. Not sure if this info is right.
Posted: Wed Jul 02, 2008 2:28 pm
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.
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Wed Jul 02, 2008 4:08 pm
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";
?>
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Wed Jul 02, 2008 5:52 pm
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.
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Wed Jul 02, 2008 6:28 pm
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.
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Wed Jul 02, 2008 7:45 pm
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.
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Wed Jul 02, 2008 7:59 pm
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.
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Wed Jul 02, 2008 8:04 pm
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.
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Sat Jul 05, 2008 12:28 am
by Ollie Saunders
Yeah I would agree with pytrin.
Try:
$host = 'localhost';
$user = 'groog_admin';
Re: Cannot connect to mysql. Not sure if this info is right.
Posted: Sun Jul 06, 2008 9:24 am
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.