MySQL : Connection problem

Status
Not open for further replies.

batiste.roger70

New Member
Messages
10
Reaction score
0
Points
0
Hello.

I can't use MySQL.

This is my PHP code:
Code:
try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=mysql-starka.x10hosting.com;dbname=test;post=3306','zagdem','mypassword');
    
    
    $reponse = $bdd->query('SELECT pseudo, message FROM Livre_or ORDER BY ID DESC LIMIT 0, 10');
    
    
    while ($donnees = $reponse->fetch())
    {
        echo '<p><strong>' . htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['message']) . '</p>';
    }
    
    $reponse->closeCursor();
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}

$reponse->closeCursor();

Of course, I have activated mysql-starka.x10hosting.com from C-panel.

When I open my page, the error is :
Erreur : SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'mysql-starka.x10hosting.com' (111)

I don't know what is wrong with it...

Thank you.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Also noticed, the username should be of the format zagdem_XXXXX where XXXXX is the user you create in MySQL databases and assign to your database.

And the database should be of the same format. 'test' is not a the full name of your database.
 

Anna

I am just me
Staff member
Messages
11,752
Reaction score
582
Points
113
When I open my page, the error is :
Erreur : SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'mysql-starka.x10hosting.com' (111)

That error could very well be the real cause, your server is stoli. mySQL host should ALWAYS be localhost.
If you are trying to connect from a location outside of the x10Hosting network it won't work as that is disabled.

$bdd = new PDO('mysql:host=mysql-starka.x10hosting.com;dbname=test;post=3306','zagdem','mypassword');

Assuming that is a copy, you have a typo, should say port=3306 not post=3306

Also both the database name and the database user must be prefixed with your cPanel name.

dbname=test; correct would be dbname=zagdem_test
Db user: zagdem (which would actually work if password in your code is your cPanel password, although not recommended); in cPanel you have two users attached: zagdem_test and zagdem_zagdem, either of those should work, if you granted correct privileges and put the correct password for the user of choice in your script
 

batiste.roger70

New Member
Messages
10
Reaction score
0
Points
0
Erreur : SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'my_local_host.x10hosting.com' (111)

This is what I get when I respect ALL your suggestions
-> zagdem_test
-> port
-> host ok

You say I don't listen to you, but you are wrong. I did not ask questions before testing things, and I had already done what you suggested without success.

Then, what do you think about the situation? The function parameters are ok now, isn't it?
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
I'm viewing the code directly on the server; is there a reason you keep changing host to something other than localhost?

Code:
$bdd = new PDO('mysql:host=religion.x10hosting.com;

Cause I can understand it possibly not working with localhost set there, HOWEVER, it will -never- work if that isn't set to localhost. If it's set to localhost and it's still having problems, then it's likely a problem with the user not actually having been given permissions to the database (which can be done via cPanel). But as long as the mysql host isn't set to Localhost, it'll never work.
 

batiste.roger70

New Member
Messages
10
Reaction score
0
Points
0
Hello,

I don't understand your answer. Of course the error is :
Erreur : SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost.x10hosting.com' (111)
Still the same problem. I wrote my_local_host to focus your attention here.

Edit : @Limewire
This is set to Localhost, and this host has been activated with Cpanel for weeks.

Edit :
Question :
How can I know, with Cpanel, what are the hosts activated? I tried several ones so several host may be activated, but I would like to make sure it worked.
Thanks.
 
Last edited:

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
Hello,

I don't understand your answer. Of course the error is :

Still the same problem. I wrote my_local_host to focus your attention here.

Edit : @Limewire
This is set to Localhost, and this host has been activated with Cpanel for weeks.

Edit :
Question :
How can I know, with Cpanel, what are the hosts activated? I tried several ones so several host may be activated, but I would like to make sure it worked.
Thanks.

it should be just localhost not the localhost.x10hosting.com
 

batiste.roger70

New Member
Messages
10
Reaction score
0
Points
0
Thank you, and sorry for not having understood before.

Now I get mySql errors from other lines of the code so the connection problem is probably solved.
 
Status
Not open for further replies.
Top