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
5b2113e5
Commit
5b2113e5
authored
May 21, 2014
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5 from screeper/master
Added table prefix feature
parents
fee1b126
e27b056b
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 @
5b2113e5
...
...
@@ -19,6 +19,12 @@ class MysqliDb
* @var MysqliDb
*/
protected
static
$_instance
;
/**
* Table prefix
*
* @var string
*/
protected
$_prefix
;
/**
* MySQLi instance
*
...
...
@@ -106,6 +112,7 @@ class MysqliDb
$this
->
port
=
$port
;
$this
->
connect
();
$this
->
setPrefix
();
self
::
$_instance
=
$this
;
}
...
...
@@ -149,6 +156,16 @@ class MysqliDb
$this
->
_query
=
null
;
$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.
...
...
@@ -214,7 +231,7 @@ class MysqliDb
$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
->
execute
();
$this
->
_stmtError
=
$stmt
->
error
;
...
...
@@ -248,7 +265,7 @@ class MysqliDb
*/
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
->
execute
();
$this
->
_stmtError
=
$stmt
->
error
;
...
...
@@ -267,7 +284,7 @@ class MysqliDb
*/
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
->
execute
();
...
...
@@ -287,7 +304,7 @@ class MysqliDb
*/
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
->
execute
();
...
...
@@ -348,7 +365,7 @@ class MysqliDb
if
(
$joinType
&&
!
in_array
(
$joinType
,
$allowedTypes
))
die
(
'Wrong JOIN type: '
.
$joinType
);
$this
->
_join
[
$joinType
.
" JOIN "
.
$joinTable
]
=
$joinCondition
;
$this
->
_join
[
$joinType
.
" JOIN "
.
$
this
->
_prefix
.
$
joinTable
]
=
$joinCondition
;
return
$this
;
}
...
...
readme.md
View file @
5b2113e5
...
...
@@ -10,6 +10,11 @@ After that, create a new instance of the class.
$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.
### Insert Query
...
...
tests.php
View file @
5b2113e5
...
...
@@ -5,6 +5,9 @@ error_reporting(E_ALL);
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'testdb'
);
if
(
!
$db
)
die
(
"Database error"
);
$prefix
=
'prefix_'
;
$db
->
setPrefix
(
$prefix
)
$tables
=
Array
(
'users'
=>
Array
(
'login'
=>
'char(10) not null'
,
...
...
@@ -92,7 +95,7 @@ function createTable ($name, $data) {
foreach
(
$tables
as
$name
=>
$fields
)
{
$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