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
1d874621
Commit
1d874621
authored
Mar 25, 2014
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to pass bind variables for func()
parent
0e8865e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
14 deletions
+33
-14
MysqliDb.php
MysqliDb.php
+27
-8
readme.md
readme.md
+6
-6
No files found.
MysqliDb.php
View file @
1d874621
...
...
@@ -433,8 +433,14 @@ class MysqliDb
$this
->
_query
.=
$prop
.
" = "
;
if
(
!
empty
(
$value
[
'[I]'
]))
$this
->
_query
.=
$prop
.
$value
[
'[I]'
]
.
", "
;
else
$this
->
_query
.=
$value
[
'[F]'
]
.
", "
;
else
{
$this
->
_query
.=
$value
[
'[F]'
][
0
]
.
", "
;
if
(
is_array
(
$value
[
'[F]'
][
1
]))
{
foreach
(
$value
[
'[F]'
][
1
]
as
$key
=>
$val
)
{
$this
->
_paramTypeList
.=
$this
->
_determineType
(
$val
);
}
}
}
}
else
{
// determines what data type the item is, for binding purposes.
$this
->
_paramTypeList
.=
$this
->
_determineType
(
$value
);
...
...
@@ -521,8 +527,14 @@ class MysqliDb
if
(
is_array
(
$val
))
{
if
(
!
empty
(
$val
[
'[I]'
]))
$this
->
_query
.=
$keys
[
$key
]
.
$val
[
'[I]'
]
.
", "
;
else
$this
->
_query
.=
$val
[
'[F]'
]
.
", "
;
else
{
$this
->
_query
.=
$val
[
'[F]'
][
0
]
.
", "
;
if
(
is_array
(
$val
[
'[F]'
][
1
]))
{
foreach
(
$val
[
'[F]'
][
1
]
as
$key
=>
$value
)
{
$this
->
_paramTypeList
.=
$this
->
_determineType
(
$value
);
}
}
}
continue
;
}
...
...
@@ -550,8 +562,15 @@ class MysqliDb
if
(
$hasTableData
)
{
$this
->
_bindParams
[
0
]
=
$this
->
_paramTypeList
;
foreach
(
$tableData
as
$prop
=>
$val
)
{
if
(
!
is_array
(
$tableData
[
$prop
]))
if
(
!
is_array
(
$tableData
[
$prop
]))
{
array_push
(
$this
->
_bindParams
,
$tableData
[
$prop
]);
continue
;
}
if
(
is_array
(
$tableData
[
$prop
][
'[F]'
][
1
]))
{
foreach
(
$tableData
[
$prop
][
'[F]'
][
1
]
as
$val
)
array_push
(
$this
->
_bindParams
,
$val
);
}
}
}
// Prepare where condition bind parameters
...
...
@@ -717,7 +736,7 @@ class MysqliDb
* @return array
*/
public
function
now
(
$diff
=
null
,
$func
=
"NOW()"
)
{
return
Array
(
"[F]"
=>
$this
->
interval
(
$diff
,
$func
));
return
Array
(
"[F]"
=>
Array
(
$this
->
interval
(
$diff
,
$func
)
));
}
/**
...
...
@@ -740,8 +759,8 @@ class MysqliDb
* Method generates user defined function call
* @param string user function body
*/
public
function
func
(
$expr
)
{
return
Array
(
"[F]"
=>
$expr
);
public
function
func
(
$expr
,
$bindParams
=
null
)
{
return
Array
(
"[F]"
=>
Array
(
$expr
,
$bindParams
)
);
}
}
// END class
readme.md
View file @
1d874621
...
...
@@ -30,13 +30,13 @@ $data = Array(
'login'
=>
'admin'
,
'firstName'
=>
'John'
,
'lastName'
=>
'Doe'
,
'fullName'
=>
$db
->
func
(
'CONCAT(firstName,
" ",lastName)'
),
// fullname = CONCAT(firstName,"",lastName)
'fullName'
=>
$db
->
func
(
'CONCAT(firstName,
?,lastName)'
,
Array
(
" "
)
),
// fullname = CONCAT(firstName,"",lastName)
'createdAt'
=>
$db
->
now
(),
// createdAt = NOW()
// createdAt = NOW()
'expires'
=>
$db
->
now
(
'+1Y'
)
// expires = NOW() + interval 1 year
// Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear
// expires = NOW() + interval 1 year
// Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear
);
$id
=
$db
->
insert
(
'users'
,
$data
)
...
...
@@ -50,7 +50,7 @@ $data = Array (
'firstName'
=>
'Bobby'
,
'lastName'
=>
'Tables'
,
'editCount'
=>
$db
->
inc
(
2
)
// editCount = editCount + 2;
// editCount = editCount + 2;
);
$db
->
where
(
'id'
,
1
);
if
(
$db
->
update
(
'users'
,
$data
))
echo
'successfully updated'
;
...
...
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