Hello i am using PDO 1st time and getting error … dont no where am i wrong here is my code
function student_one_image($student_id){
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$STH = $DBH->query("SELECT * from school_students, school_student_one_image where (school_student_one_image.student_id = school_students.student_id)
and school_student_one_image.student_id = '$student_id'");
$STH->setFetchMode(PDO::FETCH_ASSOC);
$row = $STH->fetch();
return $row
error is Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock
and if i am trying using mysql it work
function student_one_image($student_id){
$data= mysql_query("SELECT * from school_students, school_student_one_image where (school_student_one_image.student_id = school_students.student_id)
and school_student_one_image.student_id = '$student_id'");
$result = mysql_fetch_array($data);
return $result;
please help
Your variables
$host,$dbname,$userand$passare out of scope [1] since you’re using them within a function.You can either pass them like this:
Or change their scope by adding the following line to the top of your function:
[1] http://php.net/manual/en/language.variables.scope.php