Giter VIP home page Giter VIP logo

php_database_class's Introduction

PHP Database Class

A collection of class of database to call different types of database in one class

How to use it

Get new instance like this

<?php
require 'Database.php';
$db = new Database('MySQL');

setting the connection configuration

$db->driver->connect('hostname', 'database', 'username', 'password');

Basic Methods

See below basic methods to call select, update, delete and query in the class.

Select

$db_column = array(
	'column1',
	'column2'
);
			  
$db_where = array(
	'search_column_name' => 'search_value'
);
			  
$db_order = array(
	'column_name_to_order' => 'desc'
);
			  
$db->driver->select('tablename', $db_column, $db_where, $db_order);

$db->driver->execute();

Update

$db_column = array(
	'column1' => 'column1_value',
	'column2' => 'column2_value'
);
			 
$db_where = array(
				'search_column_name' => 'search_value'
			)

$db->driver->update('tablename', $db_column, $db_where);

$db->driver->execute();

Delete

$db_where = array(
	'search_column_name' => 'search_value'
)

$db->driver->delete('tablename', $db_where);

$db->driver->execute();

Fetching Data

See below methods for different ways in fething data using php database class.

Fetch Row

$db_column = array(
	'column1',
	'column2'
);
			  
$db->driver->select('tablename', $db_column);

$db->driver->execute();

foreach($db->driver->fetch_row() as $value){
	echo $value[0];
	echo $value[1];
}

Fetch Associative

$db_column = array(
	'column1',
	'column2'
);
			  
$db->driver->select('tablename', $db_column);

$db->driver->execute();

foreach($db->driver->fetch_assoc() as $value){
	echo $value['column1'];
	echo $value['column2'];
}

Fetch Object

$db_column = array(
	'column1',
	'column2'
);
			  
$db->driver->select('tablename', $db_column);

$db->driver->execute();

foreach($db->driver->fetch_object() as $value){
	echo $value->column1;
	echo $value->column2;
}

Other Database class methods

see below other useful methods of PHP Database Class.

Closing connection

$db->driver->close();

Beginning transaction

$db->driver->begin_trans();

$db_where = array(
	'search_column_name' => 'search_value'
)

$db->driver->delete('tablename', $db_where);

$db->driver->execute();

$db->driver->commit();

Rollback transaction

$db->driver->rollback();

Commiting transaction

$db->driver->commit();

php_database_class's People

Contributors

espongha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.