Can't connect to local MySQL server through socket

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Can't connect to local MySQL server through socket

Re: Can't connect to local MySQL server through socket

par moogli » 30 oct. 2012, 00:00

vire le mysql_close(), cette fonction sert à terminer la connexion, elle doit mise en fin de fichier.


@+

Re: Can't connect to local MySQL server through socket

par Oasisdudesert » 28 oct. 2012, 10:20

Merci , si je comprend bien je dois remplacer localhost, mysql_user et le pass par les miens ?

Voici ce que j'ai fais:
<?php
$link = mysql_connect("mon serveur", "login", "pass")
     or die("Impossible de se connecter : " . mysql_error());
echo 'Connexion réussie';
mysql_close($link);
?>
Et voici ce que ca me retourne

Code : Tout sélectionner

Connexion réussie Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 47 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 47 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /homez.379/mafieuxd/www/Register2.php on line 48 Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 60 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 60 Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 61 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 61 Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 62 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 62 You have successfully Registered!
Ne faut il pas renseigner la base de données à utiliser dailleur ?

Merci de votre aide, j'aimerai vraiment que ca fonctionne

Re: Can't connect to local MySQL server through socket

par sirakawa » 28 oct. 2012, 10:01

http://fr2.php.net/manual/fr/function.mysql-connect.php
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
    or die("Impossible de se connecter : " . mysql_error());
echo 'Connexion réussie';
mysql_close($link);
?>

Re: Can't connect to local MySQL server through socket

par Invité » 28 oct. 2012, 09:23

UP SVP?

Re: Can't connect to local MySQL server through socket

par Oasisdudesert » 27 oct. 2012, 19:56

UP ?

Re: Can't connect to local MySQL server through socket

par Invité » 27 oct. 2012, 16:36

Je te remerci de ton aide :

Après avoir corriger mon db_connect:
<?php
mysql_connect()
$DBTYPE = 'mysql';
$DBHOST = 'mysql51-47.perso';
$DBUSER = 'mafieuxdass';
$DBPASSWORD = 'rrzvtI0e';
$DBNAME = 'mafieuxdass';
?>
J'obtiens maintenant le message suivant :

Code : Tout sélectionner

Parse error: syntax error, unexpected T_VARIABLE in /homez.379/mafieuxd/www/includes/db_connect.php on line 3
Il semblerait que les variables utilisée pour la connexion ne correspondent pas. Où puis je les trouver ?

Re: Can't connect to local MySQL server through socket

par Ryle » 27 oct. 2012, 15:15

Dans ton fichier db_connect.php, il te manque l'appel à la fonction mysql_connect() qui va ouvrir la connexion vers la base de données avec les informations que tu as spécifié dans tes variables.

Par ailleurs, il vaut mieux utiliser "<?php" que seulement "<?" pour ouvrir une balise php

Can't connect to local MySQL server through socket

par Oasisdudesert » 27 oct. 2012, 14:46

Bonjour,
J'essai d'installer un script php sur mon site, le seul hic c'est que j'ai supprimé par erreur le fichier de connection à la BDD, j'ai tenté de le reconstituer avec les bons paramètres de connexion mais j'obtiens toujours une erreur.
Les tables sont bien crées dans la Base de Donnée.

Voici le message:
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 47

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 47

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /homez.379/mafieuxd/www/Register2.php on line 48

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 60

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 60

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 61

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 61

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /homez.379/mafieuxd/www/Register2.php on line 62

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homez.379/mafieuxd/www/Register2.php on line 62
You have successfully Registered!
Voici les 2 fichiers en cause :

Register2.php:

Code : Tout sélectionner

<html> <head> <title>Mafieuxdunet :: Register</title> <meta name="author" CONTENT="okay"> <script language="JavaScript"> <!-- function SymError() { return true; } window.onerror = SymError; //--> </script> <link REL="stylesheet" TYPE="text/css" HREF="main.css"> </head> <body bgcolor="#000000" onLoad="grabit()"> <?PHP include "includes/db_connect.php"; $datetime = gmdate('Y-m-d h:i:s'); if ($_POST['Submit'] && strip_tags($_POST['username']) && strip_tags($_POST['password']) && strip_tags($_POST['cpassword']) && strip_tags($_POST['email'])){ $ip=$_SERVER["REMOTE_ADDR"]; //draws IP address of visitor $email = $_POST['email']; $email = strip_tags($email); $username = $_POST['username']; $username = strip_tags($username); $password = $_POST['password']; $password = strip_tags($password); $cpassword = $_POST['cpassword']; $cpassword = strip_tags($cpassword); $checkname = mysql_query("SELECT * FROM users WHERE username='$username' OR email='$email'"); $NameCount = mysql_num_rows($checkname); if ($NameCount > 0) { echo "<font color=red>The username and/or email address is already in use<BR>Please <a href=\"Register2.php\">go back</a> and try again</font>"; } else{ if (!(isset($email))){ echo 'You must insert an email address and/or username!'; }else{ mysql_query("INSERT INTO `users` ( `id` , `username` , `password` , `email` ,`ip` ) VALUES ('', '$username', '$password', '$email', '$ip')"); mysql_query("INSERT INTO `crimetimes` ( `id` , `username` , `crime1` , `crime1a` , `crime2` ,`crime2a` , `crime3` , `crime3a` , `crime4` ,`crime4a` , `crime5` , `crime5a` ) VALUES ('', '$username', '', '0', '', '0', '', '0', '', '0', '', '0')"); mysql_query("INSERT INTO `signups` ( `id` , `username` , `date` ) VALUES ('', '$username', '$datetime')"); // mail user their information $yoursite = "www.mafieuxdunet.fr/"; $webmaster = "Oasis"; $youremail = "[email protected]"; $subject = "Registration Details"; $message = "Dear $username, you are now registered at mafieuxdunet.fr. To login, simply go to $yoursite and enter in the following details in the login form: Username: $username Password: $password Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "<font color=red><b>You have successfully Registered!</b></font> "; }}} ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="keywords" content="mafia, role-play, role, play, game, rpg, game"> <meta name="description" content="A multi-player game where people compete to rise through the ranks of the mafia. Commit crimes, gamble at the casino and much more!"> <title>Mafieuxdunet</title> <link href="includes/inc-style.css" type="text/css" rel="stylesheet" /> </head> <body style="margin:0px; background-image: url(images/mainbg.png); background-repeat: no-repeat; background-position: top"> <br> <br> <br> <br> <table cellspacing="0" cellpadding="0" border="0" align="center" class="main" width="585"> <tr> <td align="center"><img src="banner.jpg"></td> </tr> <tr> <td align="center"> <div style="font-weight: bold; font-size: 10pt; width: 184px">Register</div> <div style="font: 10px Verdana; color: #FF9900; text-align: center"> </div> <br /> <form action="/Register2.php" method="post"> <table cellspacing="0" cellpadding="2" border="0" align="center" class="main"> <tr class="subhdr"> <td colspan="2" align="left">* - Required fields<br></td> </tr> <tr> <td align="right" class="subhdr">Username: *</td> <td style="width: 120px"><input type="text" name="username" maxlength="100"></td> </tr> <tr> <td align="right" class="subhdr">Password: *</td> <td><input type="password" name="password" maxlength="100"></td> </tr> <tr> <td align="right" class="subhdr">Password confirm: *</td> <td><input type="password" name="cpassword"></td> </tr> <tr> <td align="right" class="subhdr">Email: *</td> <td><input type="text" name="email"></td> </tr> <tr> <td align="right" colspan="2"><input name="Submit" type="Submit" value="Submit"></td> </tr> </table> </form> </div> <center><p><a href='index.php'><b>Index</b></a></p></center>
et db_connect.php que j'ai essayé de recrée mais ne fonctionnant visiblement pas:

Code : Tout sélectionner

<? $DBTYPE = 'mysql'; $DBHOST = 'mon serveur'; $DBUSER = 'mon user'; $DBPASSWORD = 'mon pass'; $DBNAME = 'nom de la base'; ?>
Voyez vous où celà peut clocher ?