sql problem

Greg62150

New Member
Messages
6
Reaction score
0
Points
0
Bonjour,
Hello,
I created a website to develop the adsl in my french village (yes, there are some village where we don't have the adsl
triste.png
).
In order to put pressure on the mayor, I created a petition. For that, I created a sql base with 7 fields (id, firstname, surname, nickname, village, e-mail, comment) called artoinet_petition.
This database is completed by a form that redirected datas to the page "traitement-petition". This page complete the database like that :

<?php
// Connexion à la base de données
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=ftp.artoisnet.elementfx.com;dbname=artoinet_petition', 'my id', 'my password', $pdo_options);

// Insertion du message dans la table
$req = $bdd->prepare('INSERT INTO petition (pseudo, prenom, nom, email, village, commentaire) VALUES(?, ?, ?, ?, ?, ?)');
$req->execute(array($_POST['pseudo'], $_POST['prenom'], $_POST['nom'], $_POST['email'], $_POST['village'], $_POST['commentaire']));

// Redirection du visiteur vers la page petition.php
header('Location: petition.php');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>

Like that, the visitor is redirected to the page "petition.php" where we can see a table with their signatures

<?php

// Connexion à la base de données
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=ftp.artoisnet.elementfx.com;dbname=artoinet_petition', 'Identifiant', 'Mon mot de passe', $pdo_options);

// Récupération des signatures
$reponse = $bdd->query('SELECT pseudo, village, commentaire FROM petition ORDER BY ID DESC LIMIT 0, 1000');

// Affichage de chaque signature
while ($donnees = $reponse->fetch())
{
echo '<p><table><tr><td><strong>Pseudo<strong></td><td><strong>Village</strong></td><td><strong>Commentaires</strong></td></tr><tr><td>' . htmlspecialchars($donnees['pseudo']) . '</td><td>' . htmlspecialchars($donnees['village']) . '</td><td>' . htmlspecialchars($donnees['commentaire']) . '</td></tr><table></p>';
}

$reponse->closeCursor();
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}

?>

But it does not work, I have this error:

"Erreur : SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111"

This is the link of my website:
http://artoisnet.elementfx.com/artoisn [...] /petition.php

Do you know how i can resolve this problem?

Thanks a lot!!
Greg
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
Hi Greg62150,

Start by replacing

PHP:
host=ftp.artoisnet.elementfx.com

To 'localhost':
PHP:
host=localhost
 

MaestroFX1

Community Advocate
Community Support
Messages
1,577
Reaction score
60
Points
0
Well, I got this:
------
Not Found

The requested URL /artoisn was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
---------

But, after browsing a bit, I finally got your page

http://artoisnet.elementfx.com/artoisnet/artoisnet/site/petition.php

where it shows

Les signataires Erreur : SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111

and on submission
it redirects to

http://artoisnet.elementfx.com/artoisnet/artoisnet/site/traitement_petition.php

with

Erreur : SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111

Now, coming back to your problem:

ftp.artoisnet.elementfx.com should be replaced with localhost


--------
$host = "localhost";
//$port = 3306;
$var= "mysql:host=$host;dbname=$database" ;

new PDO($var, $username, $password);
 

Greg62150

New Member
Messages
6
Reaction score
0
Points
0
hello, thanks for your answers.
I tried like that :
<?php
// Connexion à la base de données
try
{
$host = "localhost";
$database = "artoinet_petition";
$var = "mysql:host=$host;dbname=$database" ;
$username = "my user name";
$password = "my password";
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;

$bdd = new PDO($var, $username, $password, $pdo_options);

// Récupération des signatures
$reponse = $bdd->query('SELECT pseudo, village, commentaire FROM petition ORDER BY ID DESC LIMIT 0, 1000');

// Affichage de chaque signature
while ($donnees = $reponse->fetch())
{
echo '<p><table><tr><td><strong>Pseudo<strong></td><td><strong>Village</strong></td><td><strong>Commentaires</strong></td></tr><tr><td>' . htmlspecialchars($donnees['pseudo']) . '</td><td>' . htmlspecialchars($donnees['village']) . '</td><td>' . htmlspecialchars($donnees['commentaire']) . '</td></tr><table></p>';
}

$reponse->closeCursor();
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>

But it does not work too, now I have this message :

Erreur : SQLSTATE[28000] [1045] Access denied for user 'artoisnet@artois'@'web8.vital.x10hosting.com' (using password: YES)

:frown:

I don't understand where come the problem...
 

Greg62150

New Member
Messages
6
Reaction score
0
Points
0

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Are you trying to access the x10hosting MySQL server from another computer and not from your x10hosting account?
 

MaestroFX1

Community Advocate
Community Support
Messages
1,577
Reaction score
60
Points
0
When you were testing, I was constantly looking at your page.
Your first attempt was the correct one, but it might have failed due to wrong password.
Now, it is incorrect again.

Try this:

<?php
// Connexion à la base de données
//make them global
$host="localhost"; // Host name
$username="artoinet_DBUSRNAME"; // Mysql username max chars 16
//artoinet_artoinet 17 chars won't work
$password="DB_PWD"; // Mysql password
$database="artoinet_petition"; // Database name
$db_conn = "mysql:host=$host;dbname=$database" ;

try
{
//FIRST
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;

$bdd = new PDO($db_conn, $username, $password, $pdo_options);

// Récupération des signatures
$reponse = $bdd->query('SELECT pseudo, village, commentaire FROM petition ORDER BY ID DESC LIMIT 0, 1000');

// Affichage de chaque signature
while ($donnees = $reponse->fetch())
{
echo '<p><table><tr><td><strong>Pseudo<strong></td><td><strong>Village</strong></td><td><strong>Commentaires</strong></td></tr><tr><td>' . htmlspecialchars($donnees['pseudo']) . '</td><td>' . htmlspecialchars($donnees['village']) . '</td><td>' . htmlspecialchars($donnees['commentaire']) . '</td></tr><table></p>';
}

$reponse->closeCursor();

//SECOND
/*
$bdd= new PDO($dsn, $username, $password);
echo "<p>Success</p>";
$bdd = null;
*/
}



catch(PDOException $e)
{
die('Erreur : '.$e->getMessage());
}
?>

It is working for me!

Use encoding : us-ascii
Check for ticks.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
No, the username is of the format artionet_abc and the database name is of the form artionet_xyz
 

MaestroFX1

Community Advocate
Community Support
Messages
1,577
Reaction score
60
Points
0
No never, why? And How can I do it?
-------
You are not, but you can.

Then, you would need to bind them or use remote mysql(which I GUESS is not enabled for Free hosting).

Again,

$host="localhost"; // Host name

$username="artoinet_DBUSRNAME"; //x10usrname_dbusrname
// Mysql username max chars 16
//artoinet_artoinet 17 chars won't work

$password="DB_PWD";
// pwd for x10usrname_dbusrname
// Mysql password


$database="artoinet_petition"; // x10usrname_dbname
// Database name
 

Greg62150

New Member
Messages
6
Reaction score
0
Points
0
Yes!!! It 's working!!
Thank you very much MaestroFX1, I would no do that without your help.
Now My website is done.
The problem comed because I didn't have link my database with my sql username.
Thanks again!
Greg
 

MaestroFX1

Community Advocate
Community Support
Messages
1,577
Reaction score
60
Points
0
It should be working now.

Delete this though
-----------
Les signataires

Pseudo Village Commentaires
Martha Paris Hmm
---------------

Bring Renaissance in your village !


Viva La Vida !
 

kjm3149

New Member
Messages
2
Reaction score
0
Points
0
If it's an x10hosting MySQL DB, be aware that:

-the db hostname should likely be "localhost"
-the db username is what is shown in cPanel
-the db name will *always* have your username prepended.

For example, if your id is "artois123" then all your databases will be name "artois123_thenameithinkitis"

Best,
KM
 
Top