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 8010199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:40:02+00:00 2026-06-04T18:40:02+00:00

I have made a function in old mysql and now want to transfer it

  • 0

I have made a function in old mysql and now want to transfer it to PDO, but its not working. Here is my new code:

global $host, $dbname, $user, $pass;
    $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    $STH = $DBH->query("SELECT SUM(score), SUM(score_from) FROM school_test_report, school_students 
    WHERE (school_test_report.student_id = school_students.student_id 
    and school_test_report.class=school_students.class) 
    and school_test_report.student_id = '$student_id' and  school_test_report.subject = '$subject'
    and school_test_report.test_date >= '$thisarch'
                                ")
    $STH->setFetchMode(PDO::FETCH_ASSOC);
    return $STH;

and it outputs:

$student_id = test_score_month($name, 'English');
echo $student_id['score'].'/'.$student_id['score_from'];

Here is old code which is working:

$result1 = mysql_query("SELECT SUM(score), SUM(score_from) FROM school_test_report, school_students 
    WHERE (school_test_report.student_id = school_students.student_id 
    and school_test_report.class=school_students.class) 
    and school_test_report.student_id = '$student_id' and  school_test_report.subject = '$subject'
    and school_test_report.test_date >= '$thisarch'
                                ")
    or die(mysql_error());  
    $row = mysql_fetch_assoc($result1);
 return $row;

and it outputs:

$student_id = test_score_month($name, 'English');
echo $student_id['score'].'/'.$student_id['score_from'];
  • 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-04T18:40:03+00:00Added an answer on June 4, 2026 at 6:40 pm

    Heres is an example, wrap all your functions todo with your querys related to your users in a model class and then call each method to return your result ect, see how the function/method uses placeholders :student_id then bindParam’s the values to thos placeholders, it is just an example but will help you understand abit more.

    <?php 
    class user_model{
    
        private $db;
    
        function __construct($host,$dbname,$user,$pass){
            $this->dbhost = $host;
            $this->dbname = $dbname;
            $this->dbuser = $user;
            $this->dbpass = $pass;
        }
    
        private function connect(){
            if (!$this->db instanceof PDO){
                $this->db = new PDO('mysql:dbname='.$this->dbname.';host='.$this->dbhost, $this->dbuser, $this->dbpass);
                $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            }
        }
    
        function user_test_score($student_id,$subject,$thisarch){
            $this->connect();
            $sql = "SELECT SUM(score) as score, SUM(score_from) FROM school_test_report, school_students
                    WHERE (school_test_report.student_id = school_students.student_id 
                    AND school_test_report.class=school_students.class) 
                    AND school_test_report.student_id = :student_id and  school_test_report.subject = :subject
                    AND school_test_report.test_date >= :thisarch";
            $statement = $this->db->prepare($sql);
            $statement->bindParam(':student_id', $student_id, PDO::PARAM_INT);
            $statement->bindParam(':subject', $subject, PDO::PARAM_STR);
            $statement->bindParam(':thisarch', $thisarch, PDO::PARAM_STR);
            $statement->execute();
            return $statement->fetchAll(PDO::FETCH_ASSOC);
        }
    
    }
    
    
    $usermodel = new user_model('localhost','YOURDB','username','password');
    
    $student_id = $usermodel->user_test_score($name,'English',your_test_date_format);
    
    print_r($student_id);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have made a function to add new upload and description inputs onClick. How
I have made a filter function but I am having trouble with the starting
I have made a function to convert a textbox value to date. I want
I have made a function that gives users instructions. When I call it I
Hi have made this function which is made to replicate an error that I
I have made a function to cound the weeks in a year, and that
I have a function made in javascript, using jQuery. I use this to send
Please help me finding where I have made mistake? delimiter // CREATE FUNCTION `count_photos_in_gallery`(`tmp_gallery_id`
ive made a function that should remove a p-element if it doesnt have any
I have a doubt regarding JNI function calls made from Android. Do they run

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.