PHP Classes

PHP MySQL Manager: Perform common MySQL database access operations

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 174 All time: 8,789 This week: 42Up
Version License PHP version Categories
php-project-structur 0.01The PHP License5PHP 5, Databases, Web services
Description 

Author

This package is specific mainly for applications used in India India .

This class can perform common MySQL database access operations.

It can connect to a MySQL database server using MySQLi. The database server details and access credentials are defined in a constants scripts.

The perform SQL queries of type SELECT, INSERT, UPDATE and DELETE using parameter values that define tables, fields, field values, condition clauses, etc..

Picture of Parag Yelonde
Name: Parag Yelonde <contact>
Classes: 1 package by
Country: India India

 

Example

<?php
/**
 * Created by PhpStorm.
 * User: parag
 * Date: 23/9/19
 * Time: 11:29 AM
 *
 */

include '../config/MySQLManager.php';
$manager = new MySQLManager();

$data = json_decode(file_get_contents('php://input'), true);

if (
$_GET['page'] == 'get_all_info') {
   
get_all_infos($manager);
}
if (
$_GET['page'] == 'get_single_info') {
   
$info_id = $_GET['info_id'];
   
get_single_info($manager, $info_id);
}
if (
$data['page'] == 'add_new_info') {
   
add_new_info($manager, $data);
}
if (
$data['page'] == 'update_info') {
   
update_info($manager, $data);
}
if (
$data['page'] == 'restore_info') {
   
restore_info($manager, $data);
}
if (
$data['page'] == 'delete_info') {
   
delete_info($manager, $data);
}
if (
$_POST['page'] == 'upload_info_image') {
   
upload_info_image($manager, $_POST, $_FILES);
}
if (
$_POST['page'] == 'send_mail') {
   
send_mail($manager, $data);
}


// get all infos
function get_all_infos($manager)
{
    try {
       
$result = $manager->select("info_master", [
           
"is_active" => 1
       
]);

        echo
json_encode(array(['res_code' => 1, 'data' => $result]));
    } catch (
Exception $e) {
    }
}

// get single info
function get_single_info($manager, $info_id)
{
    try {
       
$result = $manager->select("info_master", [
           
"is_active" => 1
       
]);

       
$result[0]['images'] = get_info_related_images($manager, $info_id);

        echo
json_encode(array(['res_code' => 1, 'data' => $result[0]]));
    } catch (
Exception $e) {
    }
}

//add_new_info
function add_new_info($manager, $data)
{
    try {
       
$first_name = $data['first_name'];
       
$last_name = $data['last_name'];
       
$email = $data['email'];
       
$password = $data['password'];
       
$role = $data['role'];
       
$is_active = 1;

       
$result = $manager->insert("info_master", [
           
"first_name" => $first_name,
           
"last_name" => $last_name,
           
"email" => $email,
           
"password" => $password,
           
"role" => $role,
           
"is_active" => $is_active,
           
"created_at" => date('Y-m-d H:i:s'),
           
"modified_at" => date('Y-m-d H:i:s')
        ]);

        if (
$result) {
           
$res = array(['res_code' => 1, 'data' => $result]);
        } else {
           
$res = array(['res_code' => 0]);
        }
        echo
json_encode($res);
    } catch (
Exception $e) {
    }
}

//update_info
function update_info($manager, $data)
{
    try {
       
$first_name = $data['first_name'];
       
$last_name = $data['last_name'];
       
$email = $data['email'];
       
$password = $data['password'];
       
$role = $data['role'];

       
$result = $manager->update("info_master", [
           
"first_name" => $first_name,
           
"last_name" => $last_name,
           
"email" => $email,
           
"password" => $password,
           
"role" => $role,
           
"modified_at" => date('Y-m-d H:i:s')
        ], [
           
"id" => $data['info_id']
        ]);

        if (
$result) {
           
$res = array(['res_code' => 1, 'data' => $result]);
        } else {
           
$res = array(['res_code' => 0]);
        }
        echo
json_encode($res);
    } catch (
Exception $e) {
    }
}

//restore_info
function restore_info($manager, $data)
{
    try {
       
$result = $manager->update("info_master", [
           
"is_active" => 1,
        ], [
           
"id" => $data['info_id']
        ]);

        if (
$result) {
           
$res = array(['res_code' => 1, 'data' => $result]);
        } else {
           
$res = array(['res_code' => 0]);
        }
        echo
json_encode($res);
    } catch (
Exception $e) {
    }
}

//delete_info
function delete_info($manager, $data)
{
    try {
       
$result = $manager->update("info_master", [
           
"is_active" => 0,
        ], [
           
"id" => $data['info_id']
        ]);

        if (
$result) {
           
$res = array(['res_code' => 1, 'data' => $result]);
        } else {
           
$res = array(['res_code' => 0]);
        }
        echo
json_encode($res);
    } catch (
Exception $e) {
    }
}

//upload image
function upload_info_image($manager, $info_data, $files)
{
    try {

       
$result = $manager->upload_file($files['image'], "../uploads/images/infos/"); //parameters image file and location where to save image file.

       
if ($result[0]['res_code']) {
            echo
json_encode($info_data);
           
$result = $manager->update("info_master", [
               
"image_url" => $result[0]['file_name'],
               
"modified_at" => date('Y-m-d H:i:s')
            ], [
               
"id" => $info_data['info_id']
            ]);
            if (
$result) {
               
$res = array(['res_code' => 1, 'data' => $result]);
            } else {
               
$res = array(['res_code' => 0]);
            }

        } else {
           
$res = array(['res_code' => 0]);
        }
        echo
json_encode($res);

    } catch (
Exception $e) {
    }
}

//get info related images
function get_info_related_images($manager, $info_id)
{
    try {
       
$result = $manager->select("info_images", [
           
"info_id" => $info_id,
        ]);

        return
$result;
    } catch (
Exception $e) {
    }
}


function
send_mail($manager, $data)
{
   
$isMailSend = $manager->send_mail($data['email_to'], $data['subject'], $data['message']);
    echo
json_encode($isMailSend);
}


Details

php_project_structure

/Author Parag Yelonde/

This Project cotain PHP Basic Project Structure


  Files folder image Files (94)  
File Role Description
Files folder imageconfig (2 files, 2 directories)
Files folder imageExample (1 file)
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:174
This week:0
All time:8,789
This week:42Up