PHP Classes
elePHPant
Icontem

MySQLi Manager: Execute MySQL queries from parameters using MySQLi

Recommend this page to a friend!
  Info   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-08-11 (1 year ago) RSS 2.0 feedStarStarStarStar 74%Total: 573 This week: 1All time: 5,190 This week: 556Up
Version License PHP version Categories
mysqli-manager 2.5GNU General Publi...5.3PHP 5, Databases
Description Author

This class can execute MySQL queries from parameters using MySQLi.

It can connect to a given MySQL server and executes queries of common types composed from parameters passed to the class.

Currently it can execute queries of types SELECT, INSERT, UPDATE and DELETE, as well multi-INSERT queries.

Recommendations

What is the best PHP mysqli class?
recommend a mysqli class

  Performance   Level  
Name: Mohamed Elbahja is available for providing paid consulting. Contact Mohamed Elbahja .
Classes: 9 packages by
Country: Morocco Morocco
Age: 22
All time rank: 11381 in Morocco Morocco
Week rank: 19 Up1 in Morocco Morocco Equal
Innovation award
Innovation award
Nominee: 3x

Details

PHP MySQLi Manager

Access MySQL database using MySQLi

Examples

example table

CREATE TABLE `example_table` (
  `id` int(11) NOT NULL,
  `title` varchar(100) CHARACTER SET utf8 NOT NULL,
  `description` varchar(150) CHARACTER SET utf8 NOT NULL,
  `text` text CHARACTER SET utf8 NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


INSERT INTO `example_table` (`id`, `title`, `description`, `text`) VALUES
(1, ' title', ' desc', ' text');

ALTER TABLE `example_table`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `example_table`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
  

Config

<?php

/
 * database config 
 */

define('DB_HOST', 'localhost'); //host
define('DB_USER', 'root'); // db username
define('DB_PASS', ''); // db password 
define('DB_NAME', 'test'); // db name

require_once('Mysqli_Manager.php');

try {

	$db = new Mysqli_Manager();
	$db->conn(); // connect DB

} catch (Exception $err) {

	exit($err->getMessage());
}

SELECT data Example

// $db->select(Column, table Name, WHERE(optional) ) 

if ( $row = $db->select('title, text', 'example_table', 'LIMIT 1')->fetch_assoc()) { 
    $title = $row['title'];
    $page_text = $row['text'];
}
unset($row);

echo $title;
echo $page_text;

//example 2
$id = $db->escape($_GET['id']); // escape 

if ( $row = $db->select('title, text', 'example_table', "WHERE id=$id") { 

    if ($row->num_rows > 0) {
        $row = $row->fetch_assoc();
        $title = $row['title'];
         $page_text = $row['text'];
    } else {
      echo 'Not Found';
    }

}
unset($row);

INSERT data


// $db->insert(table Name, array )

$data = array(
     'title' => 'Example title insert',
     'text' => 'Example data'
);

 if ($db->insert('example_table', $data) === TRUE) {
    // TRUE
    echo $db->insert_id;// get insert id
 } else {
   // FALSE
 }

Multi INSERT

$data = array(
     'insert1' => array(
            'title' => 'Example title multi insert 1',
            'text' => 'Example data multi 1'
      ),
      
     'insert2' => array(
            'title' => 'Example title multi insert 2',
            'text' => 'Example data 2'
      ), 
      
     'insert3' => array(
         'title' => 'Example title multi insert 3',
         'text' => 'Example data 3'
      ), 
);

 if ($db->multi_insert('example_table', $data) === TRUE) {
    // TRUE
   var_dump($db->insert_ids); // return array : get insert ids
 } else {
   // FALSE
 }

UPDATE data

$data = array(
     'title' => 'Updated title',
     'text' => 'Updated data'
);

if ($db->update('example_table', $data, 'WHERE id=1') === TRUE) {
    // TRUE
 } else {
   // FALSE
}

DELETE data

// $db->delete(FROM (table name), WHERE)

if( $db->delete('example_table', 'WHERE id = 1') === TRUE) {
 // deleted
} else {
 // false
}

Simple query

$query = $db->query("SELECT * FROM mbt_pages WHERE pid=1");

Close DB connetion

// close 
$db->close();
  Files folder image Files  
File Role Description
Files folder imageexamples (7 files)
Plain text file Mysqli_Manager.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file db_config.php Example Example script
  Accessible without login Plain text file example_table.sql Data Auxiliary data
  Accessible without login Plain text file insert.php Example Example script
  Accessible without login Plain text file multi_insert.php Example Example script
  Accessible without login Plain text file optimize.php Example Example script
  Accessible without login Plain text file select.php Example Example script
  Accessible without login Plain text file update_delete.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:573
This week:1
All time:5,190
This week:556Up
User Ratings User Comments (1)
 All time
Utility:93%StarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:87%StarStarStarStarStar
Examples:93%StarStarStarStarStar
Tests:-
Videos:-
Overall:74%StarStarStarStar
Rank:157
 
nice job
10 months ago (Melvira Jalisi)
57%StarStarStar