PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Akhil s Sakariya   PHP Database Operations   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: demo file
Class: PHP Database Operations
Perform common database table record operations
Author: By
Last change:
Date: 3 years ago
Size: 1,704 bytes
 

Contents

Class file image Download
<?php
//==========Include Db class=========
include("Db_operations.php");
//==========/Include Db class=========


//==============Create db Object===============
$db = new Db_operations();
//==============/Create db Object===============


//================Connection Variables=================
$server = "localhost";
$username = "root";
$password = "";
$database_name = "stud";
//================/Connection Variables=================

//=====================Get Connection======================
$connection = $db->connection($server,$username,$password,$database_name);
//=====================/Get Connection======================


//===========Define All The tables=========
$table_name = "student";
// ==========/Define All The tables=========




// insert()
// Parameters
// 1 - Db Connection
// 2 - Table Name
// 3 - Data array
// Create assoc Array Put key as table column name and value as value
$data = array('name'=>'xyz','rollno'=>11);
$db->insert($connection,$table_name,$data);


// update()
// Parameters
// 1 - Db Connection
// 2 - Table Name
// 3 - Data array
// 4 - where Condition
 
$data = array('rollno'=>99999,'name'=>'xyz');
 
$db->update($connection,$table_name,$data,'id=34');



// delete()
// Parameters
// 1 - Db Connection
// 2 - Table Name
// 3 - where Condition
 
$db->delete($connection,$table_name,"id=34");



// select()
// Parameters
// 1 - Db Connection
// 2 - Table Name
// 3 - Columns name
// 4 - where Condition

$data = array('*');
$data = array('name','id');
$data = $db->select($connection,$table_name,$data,"");
while(
$row = mysqli_fetch_assoc($data))
{
   
print_r($row);
}

?>