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
cfd0a9f9
Commit
cfd0a9f9
authored
May 21, 2014
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Revert "Merge pull request #5 from screeper/master""
This reverts commit
743541f7
.
parent
743541f7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
6 deletions
+31
-6
MysqliDb.php
MysqliDb.php
+22
-5
readme.md
readme.md
+5
-0
tests.php
tests.php
+4
-1
No files found.
MysqliDb.php
View file @
cfd0a9f9
...
@@ -19,6 +19,12 @@ class MysqliDb
...
@@ -19,6 +19,12 @@ class MysqliDb
* @var MysqliDb
* @var MysqliDb
*/
*/
protected
static
$_instance
;
protected
static
$_instance
;
/**
* Table prefix
*
* @var string
*/
protected
$_prefix
;
/**
/**
* MySQLi instance
* MySQLi instance
*
*
...
@@ -106,6 +112,7 @@ class MysqliDb
...
@@ -106,6 +112,7 @@ class MysqliDb
$this
->
port
=
$port
;
$this
->
port
=
$port
;
$this
->
connect
();
$this
->
connect
();
$this
->
setPrefix
();
self
::
$_instance
=
$this
;
self
::
$_instance
=
$this
;
}
}
...
@@ -149,6 +156,16 @@ class MysqliDb
...
@@ -149,6 +156,16 @@ class MysqliDb
$this
->
_query
=
null
;
$this
->
_query
=
null
;
$this
->
count
=
0
;
$this
->
count
=
0
;
}
}
/**
* Method to set a prefix
*
* @param string $prefix Contains a tableprefix
*/
public
function
setPrefix
(
$prefix
=
''
)
{
$this
->
_prefix
=
$prefix
;
}
/**
/**
* Pass in a raw query and an array containing the parameters to bind to the prepaird statement.
* Pass in a raw query and an array containing the parameters to bind to the prepaird statement.
...
@@ -214,7 +231,7 @@ class MysqliDb
...
@@ -214,7 +231,7 @@ class MysqliDb
$columns
=
'*'
;
$columns
=
'*'
;
$column
=
is_array
(
$columns
)
?
implode
(
', '
,
$columns
)
:
$columns
;
$column
=
is_array
(
$columns
)
?
implode
(
', '
,
$columns
)
:
$columns
;
$this
->
_query
=
"SELECT
$column
FROM
$tableName
"
;
$this
->
_query
=
"SELECT
$column
FROM
$t
his->_prefix$t
ableName
"
;
$stmt
=
$this
->
_buildQuery
(
$numRows
);
$stmt
=
$this
->
_buildQuery
(
$numRows
);
$stmt
->
execute
();
$stmt
->
execute
();
$this
->
_stmtError
=
$stmt
->
error
;
$this
->
_stmtError
=
$stmt
->
error
;
...
@@ -248,7 +265,7 @@ class MysqliDb
...
@@ -248,7 +265,7 @@ class MysqliDb
*/
*/
public
function
insert
(
$tableName
,
$insertData
)
public
function
insert
(
$tableName
,
$insertData
)
{
{
$this
->
_query
=
"INSERT into
$tableName
"
;
$this
->
_query
=
"INSERT into
$t
his->_prefix$t
ableName
"
;
$stmt
=
$this
->
_buildQuery
(
null
,
$insertData
);
$stmt
=
$this
->
_buildQuery
(
null
,
$insertData
);
$stmt
->
execute
();
$stmt
->
execute
();
$this
->
_stmtError
=
$stmt
->
error
;
$this
->
_stmtError
=
$stmt
->
error
;
...
@@ -267,7 +284,7 @@ class MysqliDb
...
@@ -267,7 +284,7 @@ class MysqliDb
*/
*/
public
function
update
(
$tableName
,
$tableData
)
public
function
update
(
$tableName
,
$tableData
)
{
{
$this
->
_query
=
"UPDATE
$tableName
SET "
;
$this
->
_query
=
"UPDATE
$t
his->_prefix$t
ableName
SET "
;
$stmt
=
$this
->
_buildQuery
(
null
,
$tableData
);
$stmt
=
$this
->
_buildQuery
(
null
,
$tableData
);
$stmt
->
execute
();
$stmt
->
execute
();
...
@@ -287,7 +304,7 @@ class MysqliDb
...
@@ -287,7 +304,7 @@ class MysqliDb
*/
*/
public
function
delete
(
$tableName
,
$numRows
=
null
)
public
function
delete
(
$tableName
,
$numRows
=
null
)
{
{
$this
->
_query
=
"DELETE FROM
$tableName
"
;
$this
->
_query
=
"DELETE FROM
$t
his->_prefix$t
ableName
"
;
$stmt
=
$this
->
_buildQuery
(
$numRows
);
$stmt
=
$this
->
_buildQuery
(
$numRows
);
$stmt
->
execute
();
$stmt
->
execute
();
...
@@ -348,7 +365,7 @@ class MysqliDb
...
@@ -348,7 +365,7 @@ class MysqliDb
if
(
$joinType
&&
!
in_array
(
$joinType
,
$allowedTypes
))
if
(
$joinType
&&
!
in_array
(
$joinType
,
$allowedTypes
))
die
(
'Wrong JOIN type: '
.
$joinType
);
die
(
'Wrong JOIN type: '
.
$joinType
);
$this
->
_join
[
$joinType
.
" JOIN "
.
$joinTable
]
=
$joinCondition
;
$this
->
_join
[
$joinType
.
" JOIN "
.
$
this
->
_prefix
.
$
joinTable
]
=
$joinCondition
;
return
$this
;
return
$this
;
}
}
...
...
readme.md
View file @
cfd0a9f9
...
@@ -10,6 +10,11 @@ After that, create a new instance of the class.
...
@@ -10,6 +10,11 @@ After that, create a new instance of the class.
$db
=
new
Mysqlidb
(
'host'
,
'username'
,
'password'
,
'databaseName'
);
$db
=
new
Mysqlidb
(
'host'
,
'username'
,
'password'
,
'databaseName'
);
```
```
It's also possible to set a table prefix:
```
php
$db
->
setPrefix
(
'tablePrefix'
);
```
Next, prepare your data, and call the necessary methods.
Next, prepare your data, and call the necessary methods.
### Insert Query
### Insert Query
...
...
tests.php
View file @
cfd0a9f9
...
@@ -5,6 +5,9 @@ error_reporting(E_ALL);
...
@@ -5,6 +5,9 @@ error_reporting(E_ALL);
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'testdb'
);
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'testdb'
);
if
(
!
$db
)
die
(
"Database error"
);
if
(
!
$db
)
die
(
"Database error"
);
$prefix
=
'prefix_'
;
$db
->
setPrefix
(
$prefix
)
$tables
=
Array
(
$tables
=
Array
(
'users'
=>
Array
(
'users'
=>
Array
(
'login'
=>
'char(10) not null'
,
'login'
=>
'char(10) not null'
,
...
@@ -92,7 +95,7 @@ function createTable ($name, $data) {
...
@@ -92,7 +95,7 @@ function createTable ($name, $data) {
foreach
(
$tables
as
$name
=>
$fields
)
{
foreach
(
$tables
as
$name
=>
$fields
)
{
$db
->
rawQuery
(
"DROP TABLE
$name
"
);
$db
->
rawQuery
(
"DROP TABLE
$name
"
);
createTable
(
$name
,
$fields
);
createTable
(
$
prefix
.
$
name
,
$fields
);
}
}
...
...
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