Mysqli Select Join Operation

Description

Select records from the multiple table with join keyword. You can provide columns to be selected and where clause with associative array of conditions with keys as columns and value as column value. You needs to specify join condition between different tables and join type (left join, right join etc.) to select data. Along with these function parameters, you can set group by columnname, order by columnname, limit, like, in , not in, between clause etc. This function will automatically creates query for you and select data.

Function Reference :
 
          	mysqli_result/array dbSelectJoin(string $table_names, array $join_conditions, array $join_type [, array $columns=array()] [, assoc. array $select_where_condition=array()]) 
                   

Parameters

Name Type Required Parameter Info Example
table_name array Yes The array of the tables to select records. e.g. array("employee_table","user_table")
join_conditions array Yes An array what we have to write the join conditions between tables. array("users.role_id=user_roles.role_id")
join_type array Yes An array which shows the type of joining between tables by its orders array("INNER JOIN","LEFT JOIN")
columns array Optional An array in which we pass all the coulmn names of tables what we required in select result array("firstname","lastname","role_name","blog_title")
select_where_condition associative array Optional An associative array in which we pass the where condition on which all the table to join array("gender"=>"male")

Examples

  
         <?php 
         $sdb= new SimplifiedDB();
         $sdb->dbConnect("localhost","username","password","dbuser");
         $sdb->parameter_types="s";
         $sdb->dbSelectJoin(array("users", "user_roles","user_blogs"), array("users.role_id=user_roles.roleid","users.userid=user_blogs.userid"), array("LEFT JOIN","RIGHT JOIN"),array("gender"=>"male")); 
 		?> 

Result

Returns result object by default. You can set $sdb->output_array=true, to return array as output.
If you use print_r($row) in
while ($rows = $result->fetch_array()) {
print_r($row);
}
it will show output as in following format.

Array ( [0] => Ram [firstName] => Ram [1] => y.ram11@gmail.com [email] => y.ram11@gmail.com ) Array ( [0] => Sachine [firstName] => Sachine [1] => y.ram11@gmail.com [email] => y.ram11@gmail.com )

Debuging

Debug Operation Result/Output
$sdb->query SELECT `firstName`,`email` FROM `users` LEFT JOIN `user_roles` ON users.role_id=user_roles.roleid RIGHT JOIN `user_blogs` ON users.userid=user_blogs.userid WHERE `gender`=?
$sdb->last_insert_id
$sdb->rows_affected
$sdb->message_info Connected to database
$sdb->error_info