PHP OOP: Using Construct To Create New Record
<p>Should I be using the __construct option to create a new record? Below is the class I have called 'Course'. I will only actually be "creating" a course 25% of the time, the rest of the time I'll want to lookup courses and what not. </p>

<pre><code>class Course {
    private $db;

    function __construct($db, $data) {
        global $error, $mysqli;

        $this-&gt;db = $db;

        requireOrError($data['course_type_id'], "Course Type Required");
        requireOrError($data['instructor_id'], "Instructor Required");
        requireOrError($data['dz_name'], "DZ Name Required");
        requireOrError($data['dz_address'], "DZ Address Required");
        requireOrError($data['dz_city'], "DZ City Required");
        requireOrError($data['dz_state'], "DZ State Required");
        requireOrError($data['dz_zip'], "DZ Zip Required");
        requireOrError($data['dz_email'], "DZ Email Required");     
        requireOrError($data['start_date'], "Course Start Date Required");
        requireOrError($data['end_date'], "Course End Date Required");
        requireOrError($data['student_slots'], "Number Of Student Slots Required");

        if(! is_numeric($data['student_slots'])) {
            $error[] = "Invalid Student Slots - Must be a number";
        }

        setError($error);

        if(empty($error)) {
            $add = $mysqli-&gt;query("INSERT INTO " . $this-&gt;db['courses'] . " (course_type_id, instructor_id, dz_name, dz_address, dz_city, dz_state, dz_zip, dz_email, start_date, end_date, student_slots, notes) VALUES ('$data[course_type_id]', '$data[instructor_id]', '$data[dz_name]', '$data[dz_address]', '$data[dz_city]', '$data[dz_state]', '$data[dz_zip]', '$data[dz_email]', '$data[start_date]', '$data[end_date]', '$data[student_slots]', '$data[notes]')");
            redirectTo("instructors.php");
        }
    }
}
</code></pre>

<p>I was going to create a function called "getCourseInfo" where I could pass an ID and it'll return the course object. Is this the best way to do it, or, should I change the __construct behavior to create. Also, could you give me an example of how I would create/lookup?</p>

<p>Thanks!</p>
