konvurt Posted July 19, 2010 Share Posted July 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208187-prepared-statements-multiple-table-select/ Share on other sites More sharing options...
bh Posted July 19, 2010 Share Posted July 19, 2010 Hi, Dont you heard about database normalization yeah? [off] I am wanting to retrieve some data from my database -> yeah, some data [/off] Quote Link to comment https://forums.phpfreaks.com/topic/208187-prepared-statements-multiple-table-select/#findComment-1088160 Share on other sites More sharing options...
konvurt Posted July 19, 2010 Author Share Posted July 19, 2010 Yes. Unfortunately, I am new to this. So I am sure I have plenty to learn. Nonetheless, I would still like any insight regarding prepared statements. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/208187-prepared-statements-multiple-table-select/#findComment-1088167 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.