This is code is made to return the name of a chosen $ID from the database,
#DB Informations (username/password)
require('/path/to/db_informations.php');
# This function return the 'name of the $ID from the db
function getName($ID){
$link = new PDO($dsn, $user, $pwd);
$query = "SELECT `name` FROM `tables` WHERE `id`=$ID";
$smt = $link->prepare($query);
$smt->execute();
$name = $smt->fetch(PDO::FETCH_ASSOC);
return $name['name'];
}
# db_informations contain the credentials to connect the database. ($dsn, $user, $pwd)
Mmh require(/path/to/db_informations.php')
is not working inside the function even if I put `require();' function in the body. I do not understand my mistake, can you please explain me:
Why the /path/to/file is not included by PHP? and How to?