Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PHP-MySQLi-Database-Class
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
PHP-MySQLi-Database-Class
Commits
65b68b2d
Commit
65b68b2d
authored
Aug 11, 2013
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added JOIN method
parent
9bf6ab7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletion
+45
-1
MysqliDb.php
MysqliDb.php
+39
-1
readme.md
readme.md
+6
-0
No files found.
MysqliDb.php
View file @
65b68b2d
...
...
@@ -30,6 +30,12 @@ class MysqliDb
* @var string
*/
protected
$_query
;
/**
* An array that holds where joins
*
* @var array
*/
protected
$_join
=
array
();
/**
* An array that holds where conditions 'fieldname' => 'value'
*
...
...
@@ -105,7 +111,9 @@ class MysqliDb
protected
function
reset
()
{
$this
->
_where
=
array
();
$this
->
_orderBy
=
array
();
$this
->
_join
=
array
();
$this
->
_orderBy
=
array
();
$this
->
groupBy
=
array
();
$this
->
_bindParams
=
array
(
''
);
// Create the empty 0 index
unset
(
$this
->
_query
);
unset
(
$this
->
_whereTypeList
);
...
...
@@ -261,6 +269,29 @@ class MysqliDb
return
$this
;
}
/**
* This method allows you to concatenates joins for the final SQL statement. Simple as a pimple.
*
* @uses $MySqliDb->join('table1', 'field1 <> field2', 'LEFT')
*
* @param string $joinTable The name of the table.
* @param string $joinCondition the condition.
* @param string $joinType 'LEFT', 'INNER' etc.
*
* @return MysqliDb
*/
public
function
join
(
$joinTable
,
$joinCondition
,
$joinType
=
''
)
{
$allowedTypes
=
array
(
'LEFT'
,
'RIGHT'
,
'OUTER'
,
'INNER'
,
'LEFT OUTER'
,
'RIGHT OUTER'
);
if
(
$joinType
&&
in_array
(
$joinType
,
$allowedTypes
))
$joinType
=
strtoupper
(
trim
(
$joinType
));
else
$joinType
=
''
;
$this
->
_join
[
$joinType
.
" JOIN "
.
$joinTable
]
=
$joinCondition
;
return
$this
;
}
/**
* This method allows you to specify multiple (method chaining optional) ORDER BY statements for SQL queries.
*
...
...
@@ -362,6 +393,13 @@ class MysqliDb
$hasTableData
=
is_array
(
$tableData
);
$hasConditional
=
!
empty
(
$this
->
_where
);
// Did the user call the "join" method?
if
(
!
empty
(
$this
->
_join
))
{
foreach
(
$this
->
_join
as
$prop
=>
$value
)
{
$this
->
_query
.=
" "
.
$prop
.
" on "
.
$value
;
}
}
// Did the user call the "where" method?
if
(
!
empty
(
$this
->
_where
))
{
...
...
readme.md
View file @
65b68b2d
...
...
@@ -131,3 +131,9 @@ $results = $db->get('tableName');
$db
->
groupBy
(
"name"
);
$results
=
$db
->
get
(
'tableName'
);
```
### JOIN method
```
php
$db
->
join
(
'table2Name'
,
'field1 <> field2'
,
'LEFT'
)
$results
=
$db
-
get
(
'tableName'
);
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment