Jump to content

Recommended Posts

Hi. I am new to Prepared Statements and have a simple question.  I am wanting to retrieve some data from my database using prepared statements however the code fails.

 

If I limit the tables selected to only one then it works fine. I have googled but haven't found an answer on whether multiple tables can be selected in a prepared statement. Any ideas?

 

My Statement (doesn't work):

 

$stmt = mysqli_prepare($this->connection, "SELECT * FROM dept_people, masterpeople WHERE masterpeople.status > 1 AND masterpeople.role = 2 AND masterpeople.id = dept_people.id");

$this->throwExceptionOnError();

 

mysqli_stmt_execute($stmt);

$this->throwExceptionOnError();

 

$rows = array();

 

mysqli_stmt_bind_result($stmt, $row->id, $row->record_status, $row->person_status, $row->payroll_lname, $row->payroll_fname, $row->payroll_mname, $row->payroll_suffix, $row->preferred_lname, $row->preferred_fname, $row->preferred_mname, $row->preferred_suffix, $row->previous_lname, $row->previous_fname, $row->sex, $row->user_group, $row->dept_unit, $row->title_payroll, $row->title_other, $row->title_other_displaycase, $row->office_building, $row->office_number, $row->office_moving_to, $row->office_phone, $row->extension, $row->voice_mail, $row->tamu_email, $row->preferred_email, $row->imported_home_address, $row->home_address_line1, $row->home_address_line2, $row->home_address_line3, $row->home_city, $row->home_state, $row->home_country, $row->home_zip, $row->home_phone, $row->cell_phone, $row->contact_note, $row->imported_forward_address, $row->forward_address_line1, $row->forward_address_line2, $row->forward_city, $row->forward_state, $row->forward_zip, $row->forward_country, $row->significant_other, $row->office_hours, $row->teaching_summer1, $row->teaching_summer2, $row->notes, $row->uin, $row->role, $row->status, $row->modOn, $row->modBy);

 

    while (mysqli_stmt_fetch($stmt)) {

      $rows[] = $row;

      $row = new stdClass();

      mysqli_stmt_bind_result($stmt, $row->id, $row->record_status, $row->person_status, $row->payroll_lname, $row->payroll_fname, $row->payroll_mname, $row->payroll_suffix, $row->preferred_lname, $row->preferred_fname, $row->preferred_mname, $row->preferred_suffix, $row->previous_lname, $row->previous_fname, $row->sex, $row->user_group, $row->dept_unit, $row->title_payroll, $row->title_other, $row->title_other_displaycase, $row->office_building, $row->office_number, $row->office_moving_to, $row->office_phone, $row->extension, $row->voice_mail, $row->tamu_email, $row->preferred_email, $row->imported_home_address, $row->home_address_line1, $row->home_address_line2, $row->home_address_line3, $row->home_city, $row->home_state, $row->home_country, $row->home_zip, $row->home_phone, $row->cell_phone, $row->contact_note, $row->imported_forward_address, $row->forward_address_line1, $row->forward_address_line2, $row->forward_city, $row->forward_state, $row->forward_zip, $row->forward_country, $row->significant_other, $row->office_hours, $row->teaching_summer1, $row->teaching_summer2, $row->notes, $row->uin, $row->role, $row->status, $row->modOn, $row->modBy);

    }

 

mysqli_stmt_free_result($stmt);

    mysqli_close($this->connection);

 

    return $rows;

}

 

Fails with:

Number of bind variables doesn't match number of fields in prepared statement

 

All the fi

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.