Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
X Lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
XLibs
X Lib
Commits
c4fbe584
Commit
c4fbe584
authored
Sep 13, 2016
by
Alex Ne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDO
parent
7615a393
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
19 deletions
+52
-19
PDO.php
Database/Driver/PDO.php
+39
-19
PDOWhereConstructor.php
Database/Driver/PDOWhereConstructor.php
+13
-0
No files found.
Database/Driver/PDO.php
View file @
c4fbe584
...
@@ -148,7 +148,7 @@ class PDO {
...
@@ -148,7 +148,7 @@ class PDO {
public
function
insert
(
$table
,
$data
,
$replace
)
{
public
function
insert
(
$table
,
$data
,
$replace
)
{
$keys
=
array_keys
(
$data
);
$keys
=
array_keys
(
$data
);
$pattern
=
array_map
(
function
(
$
string
)
{
return
":
{
$string
}
"
;},
$keys
);
$pattern
=
array_map
(
function
(
$
key
)
{
return
":
{
$key
}
"
;},
$keys
);
if
(
$replace
)
{
if
(
$replace
)
{
$type
=
"REPLACE"
;
$type
=
"REPLACE"
;
}
else
{
}
else
{
...
@@ -202,22 +202,47 @@ class PDO {
...
@@ -202,22 +202,47 @@ class PDO {
$statement
->
bindValue
(
":
{
$key
}
"
,
$data
[
$key
],
\PDO
::
PARAM_STR
);
$statement
->
bindValue
(
":
{
$key
}
"
,
$data
[
$key
],
\PDO
::
PARAM_STR
);
}
}
}
}
foreach
(
$whete_obj
->
get_dataset
()
as
$key
=>
$data_item
)
{
$whete_obj
->
bind
(
$statement
);
if
(
is_integer
(
$data_item
))
{
$statement
->
bindValue
(
$key
,
$data_item
,
\PDO
::
PARAM_INT
);
}
else
{
$statement
->
bindValue
(
$key
,
$data_item
,
\PDO
::
PARAM_STR
);
}
}
return
$statement
->
execute
();
return
$statement
->
execute
();
}
}
/**
/**
* @param $table
* @param $table
* @param array $where
* @param array $where
* @param $columns
* @param $order
* @param null $limit
* @param null $columns
* @return mixed
*/
public
function
simple
(
$table
,
$where
=
[],
$order
=
null
,
$limit
=
null
,
$columns
=
"*"
)
{
$statement
=
$this
->
select_statement
(
$table
,
$where
,
$order
,
1
,
$columns
);
if
(
$statement
->
columnCount
()
>
0
)
{
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)[
0
];
}
else
{
return
false
;
}
}
/**
* @param $table
* @param array $where
* @param $order
* @param null $limit
* @param null $columns
* @return mixed
*/
*/
public
function
select
(
$table
,
$where
=
[],
$order
=
null
,
$limit
=
null
,
$columns
=
"*"
)
{
public
function
select
(
$table
,
$where
=
[],
$order
=
null
,
$limit
=
null
,
$columns
=
"*"
)
{
return
$this
->
select_statement
(
$table
,
$where
,
$order
,
$limit
,
$columns
)
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
/**
* @param $table
* @param array $where
* @param $order
* @param null $limit
* @param null $columns
*/
public
function
select_statement
(
$table
,
$where
=
[],
$order
=
null
,
$limit
=
null
,
$columns
=
"*"
)
{
$SQL
=
"SELECT
{
$columns
}
FROM `
{
$table
}
` "
;
$SQL
=
"SELECT
{
$columns
}
FROM `
{
$table
}
` "
;
$whete_obj
=
new
PDOWhereConstructor
(
$where
);
$whete_obj
=
new
PDOWhereConstructor
(
$where
);
$SQL
.=
$whete_obj
->
get_sql
();
$SQL
.=
$whete_obj
->
get_sql
();
...
@@ -232,15 +257,10 @@ class PDO {
...
@@ -232,15 +257,10 @@ class PDO {
}
}
$statement
=
$this
->
prepare
(
$SQL
);
$statement
=
$this
->
prepare
(
$SQL
);
foreach
(
$whete_obj
->
get_dataset
()
as
$key
=>
$data_item
)
{
$whete_obj
->
bind
(
$statement
);
if
(
is_integer
(
$data_item
))
{
$statement
->
bindValue
(
$key
,
$data_item
,
\PDO
::
PARAM_INT
);
}
else
{
$statement
->
bindValue
(
$key
,
$data_item
,
\PDO
::
PARAM_STR
);
}
}
$statement
->
execute
();
$statement
->
execute
();
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
;
return
$statement
;
}
}
}
}
?>
?>
\ No newline at end of file
Database/Driver/PDOWhereConstructor.php
View file @
c4fbe584
...
@@ -192,5 +192,18 @@ class PDOWhereConstructor {
...
@@ -192,5 +192,18 @@ class PDOWhereConstructor {
private
function
not_column_operator
(
$data
)
{
private
function
not_column_operator
(
$data
)
{
if
(
is_array
(
$data
))
{
return
"NOT IN"
;}
else
{
return
"!="
;}
if
(
is_array
(
$data
))
{
return
"NOT IN"
;}
else
{
return
"!="
;}
}
}
/**
* @param $statement
*/
public
function
bind
(
&
$statement
)
{
foreach
(
$this
->
data_set
as
$key
=>
$data_item
)
{
if
(
is_integer
(
$data_item
))
{
$statement
->
bindValue
(
$key
,
$data_item
,
\PDO
::
PARAM_INT
);
}
else
{
$statement
->
bindValue
(
$key
,
$data_item
,
\PDO
::
PARAM_STR
);
}
}
}
}
}
?>
?>
\ No newline at end of file
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