• 0

check user name and password on database to verify the dataset 


Question

good dayx dear experts  hello to everyone, ;) 
 

 

i have a php-scritp that does not log to the mysql-db. it throws errors all the time: 

 

 please fix the following errors  Try again! Connection with database failed.
Reason: SQLSTATE[HY000] [2002] No such file or directory


i am not sure what goes on - if

 

my guesses 
- i use wrong credentials: 
- Socket-Problems - i.e. with the sockets cf  https://stackoverflow.com/questions/1435445/error-on-creating-connection-to-pdo-in-php

vgl pdo_mysql.default_socket=/opt/lampp/var/mysql/mysql.sock 


as for the credentials: i think i can check them with a script: 


As you see, this form authenticates the user through check_user-pass.php.  Well - It should  look for those credentials on my database; if they exist, returns OK, else returns value NO.

So my question is: exactly what code should I include in check_user-pass.php
I tried to add more code but couldn't do that as well! My current code is:


note: The name in you form is user_name but in your script you look for username

 

 

$username=$_POST['username']; 
should be

$username=$_POST['user_name']; 
EDIT:
If you use crypt to encrypt your password before you put them in the database, try this

$sql="SELECT * FROM $tbl_name WHERE username='$username'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
    $row = mysql_fetch_assoc($result);
    if (crypt($password, $row['password']) == $row['password']){
        session_register("username");
        session_register("password"); 
        echo "Login Successful";
        return true;
    }
    else {
        echo "Wrong Username or Password";
        return false;
    }
}
else{
    echo "Wrong Username or Password";
    return false;
}
EDIT: myBB seems to use a crapload of md5 hashing for their passwords, try this

$sql="SELECT * FROM $tbl_name WHERE username='$username'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
    $row = mysql_fetch_assoc($result);
    if (md5(md5($row['salt']).md5($password)) == $row['password']){
        session_register("username");
        session_register("password"); 
        echo "Login Successful";
        return true;
    }
    else {
        echo "Wrong Username or Password";
        return false;
    }
}
else{
    echo "Wrong Username or Password";
    return false;
}

 

ideas and questions 

 

 

well i just want to verify a set of user-credentials: 


- no encryption - what i want to do is  just a check of a given set of credentials
- this is what i want to do and everything should be fine.


as for the credentials: i think i can check them with a script: 


As you see, this form authenticates the user through check_user-pass.php.

 

_Idea:_ It looks for those credentials on my database; if they exist, returns OK, else returns value NO.

So my question is: exactly what code should I include in check_user-pass.php?
 

 

 

regards 

 

update: 

 

i can do this with a spimple test the connection script too: 

 

 error in establishing db bei dem Versuch ein Script zu installieren. 
 - mit einem Testconnection-Script versucht das weiterzuverfolgen:

<?php
if(function_exists('mysqli_connect')){
if(!($link = mysqli_connect('localhost','username','password','my_db'))){
die('could not connect: ' . mysqli_error($link));
}
} else {
die("don't have mysqli");
}
echo 'connect successfully';
mysqli_close($link);

 

Edited by tarifa

3 answers to this question

Recommended Posts

  • 0

It looks like you're trying to connect to the database using a unix socket which doesn't exist. Can you post the code you're using to establish the database connection?

 

Are you sure the database is listening on a socket, and not on a TCP port? If so, what is the path to that socket?

  • 0
  On 30/09/2019 at 10:13, DaveLegg said:

It looks like you're trying to connect to the database using a unix socket which doesn't exist. Can you post the code you're using to establish the database connection?

 

Are you sure the database is listening on a socket, and not on a TCP port? If so, what is the path to that socket?

Expand  

Good day dear dave 

 

many many thanks for the quick reply.  i have 

 

 

the above mentioned script should help out  - since i am in a situation where i have issues with connecting to a mysql-server - during the installation of a script: 

 

since i get this annoying error in establishing db

 



while trying to install limesurvey on my server i get back the following error

could not connect to the db: reason : SQLSTATE[HY000] [2002] No such file or directory  


 

well Dave i will try the Testconnection-Script (see below) to help out to verify the data

 

see the  Testconnection-Script 

<?php
if(function_exists('mysqli_connect')){
if(!($link = mysqli_connect('localhost','username','password','my_db'))){
die('could not connect: ' . mysqli_error($link));
}
} else {
die("don't have mysqli");
}
echo 'connect successfully';
mysqli_close($link);

 


hopefully i will get more insights

 

 


tried it several times - but without any success;: i googled the error


Quick test (run in shell):

 php -r "new PDO('mysql:hostname=localhost;dbname=test', 'username', 'password');" SQLSTATE[HY000] [2002] No such file or directory means php cannot find the mysql.default_socket file. Fix it by modifying php.ini file. On Mac it is mysql.default_socket = /tmp/mysql.sock (See PHP - MySQL connection not working: 2002 No such file or directory) SQLSTATE[HY000] [1044] Access denied for user 'username'@'localhost' CONGRATULATION! You have the correct mysql.default_socket setting now. Fix your dbname/username/password. Also see Error on creating connection to PDO in PHP



and the following ideas: see an interesting thread on stackoverflow: https://stackoverflow.com/questions/29695450/pdoexception-sqlstatehy000-2002-no-such-file-or-directory

  Quote

 

You need to change host from localhost to 127.0.0.1 Laravel 4: In your app/config/database.php try changing host from localhost to 127.0.0.1 Laravel 5: In the .env file, change DB_HOST from localhost to 127.0.0.1 Source: PDOException SQLSTATE[HY000] [2002] No such file or directory shareeditflag  

Expand  


 

: see an interesting thread on stackoverflow: https://stackoverflow.com/questions/29695450/pdoexception-sqlstatehy000-2002-no-such-file-or-directory

 

Well Dave i hope that i will get more insights with the above mentionend Test the conection-script. 

 

 

love to hear from you 

 

regards 

  • 0

Find out from your hosting provider if the MySQL server is listening on a socket (and if so which path), or only via IP - if so, connect via IP as in the example you just posted. There's no way for us to know how your hosting provider has configured your MySQL server - you need to find this out.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Burrrrn. Bought COD WWII last month when it was on sale for PC. Oh well. Excellent game tho, and the PC version plays/looks amazing (and has it's own PC achievements). ...wondering if this is a lesson on waiting on sales. ...also hoping Rise of the Tomb Raider has it's own PC Achievements
    • Google Chrome 137.0.7151.120 (offline installer) by Razvan Serea The web browser is arguably the most important piece of software on your computer. You spend much of your time online inside a browser: when you search, chat, email, shop, bank, read the news, and watch videos online, you often do all this using a browser. Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier. Use one box for everything--type in the address bar and get suggestions for both search and Web pages. Thumbnails of your top sites let you access your favorite pages instantly with lightning speed from any new tab. Desktop shortcuts allow you to launch your favorite Web apps straight from your desktop. Chrome has many useful features built in, including automatic full-page translation and access to thousands of apps, extensions, and themes from the Chrome Web Store. Google Chrome is one of the best solutions for Internet browsing giving you high level of security, speed and great features. Important to know! The offline installer links do not include the automatic update feature. Google Chrome 137.0.7151.120 changelog: [$7000][420697404] High CVE-2025-6191: Integer overflow in V8. Reported by Shaheen Fazim on 2025-05-27 [$4000][421471016] High CVE-2025-6192: Use after free in Profiler. Reported by Chaoyuan Peng (@ret2happy) on 2025-05-31 [425443272] Various fixes from internal audits, fuzzing and other initiatives Download web installer: Google Chrome Web 32-bit | Google Chrome 64-bit | Freeware Download: Google Chrome Offline Installer 64-bit | 128.0 MB Download: Google Chrome Offline Installer 32-bit | 115.0 MB Download page: Google Chrome Portable Download: Google Chrome MSI Installers for Windows (automatic update) View: Chrome Website | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • -Drop the art style, it's cool but doesn't fit the franchise at all. -Make it a gritty single player game, like Halo -Include deathmatch and all that stuff, extraction can be a separate mode If they don't do that, it's dead on arrival IMO.
  • Recent Achievements

    • One Month Later
      Custom Greek Shirts earned a badge
      One Month Later
    • Week One Done
      Custom Greek Shirts earned a badge
      Week One Done
    • One Year In
      Custom Greek Shirts earned a badge
      One Year In
    • Week One Done
      topantidetectbrowser earned a badge
      Week One Done
    • Explorer
      Jdoe25 went up a rank
      Explorer
  • Popular Contributors

    1. 1
      +primortal
      672
    2. 2
      ATLien_0
      281
    3. 3
      Michael Scrip
      223
    4. 4
      +FloatingFatMan
      190
    5. 5
      Steven P.
      145
  • Tell a friend

    Love Neowin? Tell a friend!