PDO Join Function multi table join database operation using GOModel


GOModel join functions allows to select data from multiple tables using various JOIN operation. You need to specify join table, join condition and type of join ("LEFT JOIN", "INNER JOIN"). You can apply all select operations functions with join operation also.

Function Defination

                                void function joinTables($joinTableName, $joinCondition, $joinType = "INNER JOIN") ;

Parameters Details

Details Type Example
$joinTableName - table name, to perform join query string Any valid tablename e.g. "select * from tablename"
$joinCondition - condition by which tables will be joined string e.g. "wp_posts.ID = wp_postmeta.post_id"
$joinType - type of join string Any valid jointype e.g. "INNER JOIN", "LEFT JOIN", default is INNER JOIN


                                $GOModel = new GOModel(); //create object of the GOModel class
                                $GOModel->connect("localhost", "root", "", "database");//connect to database
                                /* Join function */
                                $GOModel->joinTables("wp_postmeta", "wp_posts.ID = wp_postmeta.post_id","INNER JOIN");//specify join
                                $result =  $GOModel->select("wp_posts");//call select query

More Examples

                                //Example 1 
                                $GOModel->columns = array("wp_posts.id", "post_date", "post_title");
                                $GOModel->joinTables("wp_postmeta", "wp_posts.ID = wp_postmeta.post_id","INNER JOIN");
                                $GOModel->limit = "0,3";
                                $result =  $GOModel->select("wp_posts");

                                //Example 2
                                $GOModel->columns = array("p.id", "post_date", "post_title");
                                $GOModel->where("post_title", "P%", "LIKE");
                                $GOModel->where("post_date", array('2016-03-01','2016-03-10'), "BETWEEN");
                                $GOModel->joinTables("wp_postmeta as pm", "p.ID = pm.post_id","LEFT OUTER JOIN");
                                $GOModel->limit = "0,3";
                                $result =  $GOModel->select("wp_posts as p");



By default, it returns data in associative array format. You can set return type using the fetch mode.


Option Details Example
$GOModel->getLastQuery(); Return last query executed SELECT `p`.`id`,`post_date`,`post_title` FROM `wp_posts` AS `p` LEFT OUTER JOIN `wp_postmeta` AS `pm` ON p.ID = pm.post_id WHERE `post_title`LIKE ? AND `post_date` BETWEEN ? AND ? LIMIT 0,3
print_r($GOModel->error) Print errors (if any)
$GOModel->totalRows; Total rows returned for select query 10