PHP Classes

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    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 74%Total: 662 This week: 1All time: 4,865 This week: 560Up
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.

Picture of Mohamed Elbahja
  Performance   Level  
Name: Mohamed Elbahja is available for providing paid consulting. Contact Mohamed Elbahja .
Classes: 12 packages by
Country: Morocco Morocco
Age: 29
All time rank: 9041 in Morocco Morocco
Week rank: 106 Up1 in Morocco Morocco Equal
Innovation award
Innovation award
Nominee: 4x

Recommendations

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

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:662
This week:1
All time:4,865
This week:560Up
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:97
 
nice job
7 years ago (Melvira Jalisi)
57%StarStarStar