Mysql 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, group by, order by , limit etc. You needs to specify join condition between different tables and join type (LEFT JOIN,RIGHT JOIN etc.) to select data. This function will automatically creates query for you and select data.

Function Reference :
 
          	resource/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 name of the table to insert new records any table name like array("employee_table","user_table")
join_conditions array Yes Array of join conditions between tables. array("users.role_id=user_roles.role_id")
join_type array Yes Array of join types array("INNER JOIN","LEFT JOIN")
columns_array array Optional Array of columns to be selected array("firstname","lastname","role_name","blog_title")
select_where_condition associative array Optional Associative array with key as column name and values as column value for where clause. array("gender"=>"male")

Examples

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

Result

Returns mysql result set by default. You can set $sdb->output_array=true, to return array as output.
If you use print_r($row) in
while($row = mysql_fetch_array($result)) {
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] => s.sachin@gmail.com [email] => s.sachine@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
$sdb->last_insert_id
$sdb->rows_affected
$sdb->message_info Connected to database
$sdb->error_info

More Examples

             <?php 
             $tables=array("users", "user_roles");
             $joins=array("users.role_id=user_roles.roleid");
             $join_condition=array("LEFT JOIN");
             $columns=array("firstName", "email", "role_name","blogTitle","content");
             $whereCondition=array("gender"=>"male");
             $sdb->dbSelectJoin($tables,$joins,$join_condition,$columns,$whereCondition); 
             ?>