Skip to content

Commit

Permalink
How to use PRC
Browse files Browse the repository at this point in the history
  • Loading branch information
asakpke committed Nov 23, 2023
1 parent ef6fa84 commit 4a2490b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
12 changes: 0 additions & 12 deletions Example1/Example1.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@ function __construct()

parent::__construct();

// $this->auth = "WHERE user_id = {$_SESSION['user_id']}"; // we may adjust or fix it later on
$this->tbl['cols'] = array(
// 'id' => array(
// 'type' => 'text',
// 'display as' => 'ID',
// 'is display' => array(
// 'on listing' => false,
// 'on view' => false,
// 'on add' => false,
// 'on edit' => false,
// ),
// 'is required' => true,
// ),
'name' => array(
'type' => 'text',
'display as' => 'Name',
Expand Down
16 changes: 1 addition & 15 deletions PRC.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PRC
'name' => 'PHP RAD CRUD',
'nameShort' => 'PRC',
'desc' => 'PHP - PHP: Hypertext Preprocessor. RAD - Rapid Application Development. CRUD - Create, Read, Update and Delete',
'version' => '0.1.2',
'version' => '0.1.3',
'developer' => 'Aamir Shahzad',
'path' => '/opt/lampp/htdocs/PRC',
'pathUrl' => 'http://localhost/PRC',
Expand Down Expand Up @@ -87,18 +87,14 @@ function __construct($opt = null)
function list()
{
$cols = $this->getCols('on listing');

$sql = "SELECT {$this->tbl['name']}.id, {$cols['fields']} FROM {$this->tbl['name']};";
// prd($sql,'$sql');

$result = mysqli_query(
$this->dbConn,
$sql
);

if (mysqli_num_rows($result)) {
$row = mysqli_fetch_assoc($result);
// $cols = array_keys($row);
} // if num_rows
?>
<main>
Expand Down Expand Up @@ -290,8 +286,6 @@ function edit($id)
$cols = $this->getCols('on edit');

$sql = "SELECT {$this->tbl['name']}.id, {$cols['fields']} FROM {$this->tbl['name']} WHERE id = $id LIMIT 1;";
// prd($sql,'$sql');

$result = mysqli_query(
$this->dbConn,
$sql
Expand Down Expand Up @@ -358,11 +352,7 @@ function blob($id, $name)
$stmt = mysqli_prepare(
$this->dbConn,
"SELECT {$this->tbl['name']}.$name FROM {$this->tbl['name']} WHERE {$this->tbl['name']}.id = ? LIMIT 1;"
// "SELECT {$this->tbl['name']}.$name FROM {$this->tbl['name']} {$this->auth} AND {$this->tbl['name']}.id = ? LIMIT 1;"
);

// print_r($result);

mysqli_stmt_bind_param($stmt, "i", $id);

if (mysqli_stmt_execute($stmt) === true) {
Expand Down Expand Up @@ -448,7 +438,6 @@ function login()
$row = $result->fetch_assoc();

if (!empty($row)) {
// $_SESSION['user_id'] = $row['id'];
$_SESSION['user'] = $row;
$color = 'green';
header("Location: {$this->app['pathUrl']}/index.php?msg={$msg}&color={$color}");
Expand Down Expand Up @@ -495,7 +484,6 @@ function index()

function logout()
{
// $_SESSION['user_id'] = 0;
$_SESSION['user'] = null;
$msg = 'You are logged out successfully.';
$color = 'green';
Expand Down Expand Up @@ -559,7 +547,5 @@ function showMsg()
{
if (!empty($_GET['msg'])) {
echo "<p style=\"color:{$_GET['color']}\">{$_GET['msg']}</p>";
// $_GET['msg'] = '';
// $_GET['color'] = '';
} // if GET msg
} // showMsg()
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
PHP RAD CRUD
- PHP - PHP: Hypertext Preprocessor
- RAD - Rapid Application Development
- CRUD - Create, Read, Update and Delete
- CRUD - Create, Read, Update and Delete

## How to use?
Update your database details at PRC.php file.

You can use example.sql database for testing.

Create new folder for each database table and follow code examples given at
- Example1 folder
- Example2 folder
- Users folder

0 comments on commit 4a2490b

Please sign in to comment.