jfr's avatar
Level 1

SQLSTATE[HY000] [2002] No such file or directory

Hello,

I get this error:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `results` where `finalHouse` = ravenclaw)

in Connection.php line 664
at Connection -> runQueryCallback( 'select * from `results` where `finalHouse` = ?', array('ravenclaw'), object( Closure) )
in Connection.php line 624
at Connection -> run( 'select * from `results` where `finalHouse` = ?', array('ravenclaw'), object( Closure) )
in Connection.php line 333

(yes, I'm building a harry potter test ;) )

This is the code I'm writing:

$houses = ['ravenclaw', 'gryffindor', 'hufflepuff', 'slytherin'];
$results = [];
foreach ($houses as $key => $house) {
    $results[$key] = DB::table('results')->select('*')->where('finalHouse', $house)->get();
}   

$house is always a string, also when I var_dump it. I tried several things, but it kind of converts the string to... whatever it is? It is converting in the get(), in the getBindings() array is the string still a string. finalHouse is an enum in the database (also changed it to varchar, but doesn't make a difference). Using PHP 7.2.14 and Lumen 5.8. Can anyone help me? I have the feeling I oversee something really obvious.

0 likes
4 replies
bobbybouwmann's avatar

Are you sure you're using the correct database connection? Sometimes you need to use a different host when you get this message

Also are you sure the table and column exist in the database?

jfr's avatar
Level 1

Yes, the database connection exists and without the where the query also works. Table and column both exist, I can also write into the results table.

bobbybouwmann's avatar

So how did you test the database at this point? From the application or from some third party tool?

jfr's avatar
Level 1

I dumped the database connection in the application + all other queries in the application work, it's only this query that doesn't work.. I implemented a workaround this morning, maybe it's something with the PHP version on the server or something else. Locally everything works normal. But thank you for your help!

Please or to participate in this conversation.