Simple MySQLi database access wrapper: Connect and query a MySQL database using MySQLi

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-04-26 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 180 All time: 8,498 This week: 117Up
Version License PHP version Categories
mysqli_wrapper 1.0Freely Distributable7.3.0Databases
Description Author

This class can Connect and query a MySQL database using the MySQLi extension.

It can read and parse a configuration file in the INI format and establishes a connection to a MySQL database server using connection parameters obtained from that configuration file.

The class can also perform several types of operations to access the MySQL database like:

1. Connect to Database
2. Query the database
3. Query the database for number of Rows (mysqli_num_rows)
4. Fetch rows from the database (SELECT query)
5. Fetch the last error from the database
6. Fetch the last Insert Id from the database
7. Quote and escape value for use in a database query

  Performance   Level  
Name: Chetankumar Digambarrao ... <contact>
Classes: 2 packages by
Country: India India
Age: 37
All time rank: 2809176 in India India
Week rank: 616 Up61 in India India Up

Details
# Simple MySQLi database access wrapper
In this document you can find proper usage of this library.
By - Chetankumar Akarte
for help email me - chetan.akarte@gmail.com
get connect @ https://www.linkedin.com/in/chetanakarte

### About
This class is used to Connect and query a MySQL database using the MySQLi.extension.

### Requirements
- PHP: >=7.3.0

### Overview
This class library can read and parse a configuration file in the INI format and establishes a connection to a MySQL database server using connection parameters obtained from that configuration file.


### Usage
First you need to update config.ini with your database details and keep it in the same folder where your have db.php
```php
localhost = localhost 	//MySQL Host 
username = root			//MySQL User
password = ''			//MySQL Password
dbname = classic_news	//MySQL Database
```

Include db.php where you want to used MySQL data and initializa class.

```php
require_once('db.php');
$DB = new DB;
```

### Execute Query

```php
$query = "SELECT * tbl_category";
$DB->query($query);

```

### Process Query Result - 1st Row

```php
$query = "SELECT * tbl_category";
$get_cat = $DB->select($query);
	if(count($get_cat) > 0){
		$_cid= $get_cat[0]['cid'];
		$_catName = $get_cat[0]['category_name'];
		$_catStatus = $get_cat[0]['category_status'];
		$_imgDefault = $get_cat[0]['category_image'];
		$_catSequence = $get_cat[0]['category_sequence'];
		
	}
```

### Process Query Result - All Row

```php
$query = "SELECT * tbl_category";
$get_cat = $DB->select($query);
	if(count($get_cat) > 0){
	foreach ($category_check as $get_cat) {
		$_cid= $get_cat['cid'];
		$_catName = $get_cat['category_name'];
		$_catStatus = $get_cat['category_status'];
		$_imgDefault = $get_cat['category_image'];
		$_catSequence = $get_cat['category_sequence'];
		}
	}
```


### Fetch the last Insert Id from the database

```php
$query = "INSERT INTO tbl_news (featured, news_title, news_cat, news_description, news_cover_img,published_on) VALUES('".trim($_POST['isFeatured'])."','".trim($_POST['txtTitle'])."','".$_cid."','".$strDummy."','".$file_name."', now())";
	//echo $query;
	$DB->query($query);
	$_insetId=$DB->insert_id();
	//print_r($_insetId);
```
  Files folder image Files  
File Role Description
Accessible without login Plain text file config.ini Data MySQL database configuration
Plain text file db.php Class Class File
Accessible without login Plain text file Readme Doc. Documentation - How to used this Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:180
This week:0
All time:8,498
This week:117Up

For more information send a message to info at phpclasses dot org.