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
a5f25d09
Commit
a5f25d09
authored
May 02, 2014
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New sample CRUD index.php and some readme updates
parent
733bcdaf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
15 deletions
+113
-15
index.php
index.php
+110
-12
readme.md
readme.md
+3
-3
No files found.
index.php
View file @
a5f25d09
<?php
require_once
(
'MysqliDb.php'
);
error_reporting
(
E_ALL
);
$action
=
'adddb'
;
$data
=
array
();
$db
=
new
MysqliDb
(
'localhost'
,
'root'
,
'root'
,
'db'
);
function
printUsers
()
{
global
$db
;
$users
=
$db
->
get
(
"users"
);
if
(
$db
->
count
==
0
)
{
echo
"<td align=center colspan=4>No users found</td>"
;
return
;
}
foreach
(
$users
as
$u
)
{
echo
"<tr>
<td>
{
$u
[
'id'
]
}
</td>
<td>
{
$u
[
'login'
]
}
</td>
<td>
{
$u
[
'firstName'
]
}
{
$u
[
'lastName'
]
}
</td>
<td>
<a href='index.php?action=rm&id=
{
$u
[
'id'
]
}
'>rm</a> ::
<a href='index.php?action=mod&id=
{
$u
[
'id'
]
}
'>ed</a>
</td>
</tr>"
;
}
}
function
action_adddb
()
{
global
$db
;
$data
=
Array
(
'login'
=>
$_POST
[
'login'
],
'customerId'
=>
1
,
'firstName'
=>
$_POST
[
'firstName'
],
'lastName'
=>
$_POST
[
'lastName'
],
'password'
=>
$db
->
func
(
'SHA1(?)'
,
Array
(
$_POST
[
'password'
]
.
'salt123'
)),
'createdAt'
=>
$db
->
now
(),
'expires'
=>
$db
->
now
(
'+1Y'
)
);
$id
=
$db
->
insert
(
'users'
,
$data
);
header
(
"Location: index.php"
);
exit
;
}
function
action_moddb
()
{
global
$db
;
$data
=
Array
(
'login'
=>
$_POST
[
'login'
],
'customerId'
=>
1
,
'firstName'
=>
$_POST
[
'firstName'
],
'lastName'
=>
$_POST
[
'lastName'
],
);
$id
=
(
int
)
$_POST
[
'id'
];
$db
->
where
(
"customerId"
,
1
);
$db
->
where
(
"id"
,
$id
);
$db
->
update
(
'users'
,
$data
);
header
(
"Location: index.php"
);
exit
;
}
function
action_rm
()
{
global
$db
;
$id
=
(
int
)
$_GET
[
'id'
];
$db
->
where
(
"customerId"
,
1
);
$db
->
where
(
"id"
,
$id
);
$db
->
delete
(
'users'
);
header
(
"Location: index.php"
);
exit
;
}
function
action_mod
()
{
global
$db
;
global
$data
;
global
$action
;
$action
=
'moddb'
;
$id
=
(
int
)
$_GET
[
'id'
];
$db
->
where
(
"id"
,
$id
);
$data
=
$db
->
getOne
(
"users"
);
}
$db
=
new
Mysqlidb
(
'localhost'
,
'root'
,
''
,
'testdb'
);
if
(
$_GET
)
{
$f
=
"action_"
.
$_GET
[
'action'
];
if
(
function_exists
(
$f
))
{
$f
();
}
}
?>
<!DOCTYPE html>
...
...
@@ -9,19 +94,32 @@ $db = new MysqliDb('localhost', 'root', 'root', 'db');
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<title>
untitled
</title>
<title>
Users
</title>
</head>
<body>
<?php
$insertData
=
array
(
'title'
=>
'Inserted title'
,
'body'
=>
'Inserted body'
);
$results
=
$db
->
insert
(
'posts'
,
$insertData
);
print_r
(
$results
);
?>
<center>
<h3>
Users:
</h3>
<table
width=
'50%'
>
<tr
bgcolor=
'#cccccc'
>
<th>
ID
</th>
<th>
Login
</th>
<th>
Name
</th>
<th>
Action
</th>
</tr>
<?php
printUsers
();
?>
</table>
<hr
width=
50%
>
<form
action=
'index.php?action=
<?php
echo
$action
?>
'
method=
post
>
<input
type=
hidden
name=
'id'
value=
'
<?php
echo
$data
[
'id'
]
?>
'
>
<input
type=
text
name=
'login'
required
placeholder=
'Login'
value=
'
<?php
echo
$data
[
'login'
]
?>
'
>
<input
type=
text
name=
'firstName'
required
placeholder=
'First Name'
value=
'
<?php
echo
$data
[
'firstName'
]
?>
'
>
<input
type=
text
name=
'lastName'
required
placeholder=
'Last Name'
value=
'
<?php
echo
$data
[
'lastName'
]
?>
'
>
<input
type=
password
name=
'password'
placeholder=
'Password'
>
<input
type=
submit
value=
'New User'
></td>
<form>
</table>
</center>
</body>
</html>
\ No newline at end of file
</html>
readme.md
View file @
a5f25d09
...
...
@@ -19,7 +19,7 @@ $data = Array ("login" => "admin",
"firstName"
=>
"John"
,
"lastName"
=>
'Doe'
)
$id
=
$db
->
insert
(
'users'
,
$data
)
$id
=
$db
->
insert
(
'users'
,
$data
)
;
if
(
$id
)
echo
'user was created. Id='
.
$id
;
```
...
...
@@ -39,7 +39,7 @@ $data = Array(
// Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear
);
$id
=
$db
->
insert
(
'users'
,
$data
)
$id
=
$db
->
insert
(
'users'
,
$data
)
;
if
(
$id
)
echo
'user was created. Id='
.
$id
;
```
...
...
@@ -91,7 +91,7 @@ echo $user['id'];
### Delete Query
```
php
$db
->
where
(
'id'
,
1
);
if
(
$db
->
delete
(
'
posts'
))
echo
'successfully deleted'
;
if
(
$db
->
delete
(
'
users'
))
echo
'successfully deleted'
;
```
### Generic Query Method
...
...
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