Please help, i cannot understand what is error

Website URL

https://studynow.free.nf

Error Message

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /home/vol16_2/infinityfree.com/if0_35990726/htdocs/mysql.php:4 Stack trace: #0 /home/vol16_2/infinityfree.com/if0_35990726/htdocs/mysql.php(4): PDO->__construct(‘mysql:host = sq…’, ‘if0_35990726’, Object(SensitiveParameterValue)) #1 /home/vol16_2/infinityfree.com/if0_35990726/htdocs/index.php(3): require(‘/home/vol16_2/i…’) #2 {main} thrown in /home/vol16_2/infinityfree.com/if0_35990726/htdocs/mysql.php on line 4

Other Information

i checked the docs and there is says not to use localhost here i selected my host still error.

Can you share your code? Be sure to block out the password

4 Likes
<?php

$dsn = "mysql:host = sql300.infinityfree.com; port=3306; dbname=if0_35990726_student_data;";

$pdo = new PDO($dsn, 'if0_35990726','*********');

$query = $pdo->prepare("select * from user_data;");

$query->execute();

$data = $query->fetchall();

$pdata = var_dump($data);

echo "<pre>{$pdata}</pre>";

done done i used mysqli and its working

A “No such file or directory” error when using MySQL always means you’re using localhost as the database hostname.

Using either MySQLi or PDO should be fine. However, please note that with a PDO connection string, you cannot add spaces to it for formatting and still expect it to work. The parameter host<space> is not the same as host, and <space>sql300.infinityfree.com is not the same as sql300.infinityfree.com.

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.