Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:31:33+00:00 2026-06-04T06:31:33+00:00

Hello i am using PDO 1st time and getting error … dont no where

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:31:35+00:00Added an answer on June 4, 2026 at 6:31 am

    Your variables $host, $dbname, $user and $pass are out of scope [1] since you’re using them within a function.
    You can either pass them like this:

    function student_one_image($student_id, $host, $dbname, $user, $pass) {
    

    Or change their scope by adding the following line to the top of your function:

    global $host, $dbname, $user, $pass;
    

    [1] http://php.net/manual/en/language.variables.scope.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys Im using advance notification manager this is the code Notification note =
I'm getting an error when I try to decrypt using PostgreSQL's gnupg extension and
hello i'm using this .htaccess code to redirect urls. RewriteEngine on RewriteRule ^printer/([^/\.]+)/?$ printer.php?id=$1
hello i am using httpUnit and i have the following error org.mozilla.javascript.EcmaError: TypeError: Cannot
Hello I´m trying using the next piece of code: import pickle object = Object()
Hello I am using the following code to linkify email addresses and urls and
hello im using this code to do search <form action=arama.php method=get> <input type=text name=lol>
I have to read a file called hello.txt using the following code on java/eclipse/android:
Hello I am using this jquery code onclick=jQuery('.hidden').show() to show the class labeled .hidden
Hello i am new to PDO so getting confused and getting errors ;) with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.