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

accessing localhost xampp from another computer

  1. Go to Your XAMPP Control panel
  2. Click on apache > config > Apache (httpd.conf)
  1. Search for Listen 80 and replace with Listen 8080
  2. After that check your local ip using ipconfig command (cmd console)
  3. Search for ServerName localhost:80 and replace with your local ip:8080 (ex.192.168.1.156:8080)
  4. After that open apache > config > Apache (httpd-xampp.conf)
  1. Search for <Directory "C:/xampp/phpMyAdmin"> AllowOverride AuthConfig **Require local** Replace with **Require all granted** ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var </Directory>```
  2. Go to xampp > config > click on service and port setting and change apache port 8080
  3. restart xampp
  4. then hit your IP:8080 (ex.192.168.1.156:8080) from another computer

php code need on developent

Array

array as function parameter

$a=array("table_name"=>"userinfo");
echo $crud->find($a);

return array value

$sql["table_name"];

array inside string

public function find($sql) {
        $query="select * from {$sql["table_name"]}";
        echo $query; 
    }

Php Pdo Database Connection class

php pdo নিয়ে কাজ করার জন্য আমরা নিচের পদ্ধতি অনুসরণ করবো।
প্রথমে আমরা একটি ক্লাস তৈরী করবো এবং এর মধ্যে আমাদের কানেকশন এর কোডটি রাখবো এবং যখন কোনো সময় আমাদের কানেক্শনটি দরকার হবে তখন সিম্পলি আমরা এটাকে বেবহার করবো।
নিচের কানেকশন ক্লাসটি আমি ২০১৮ সালে নিজের মতো করে বানিয়েছি যেটা বেবহার করে (sql ,mysql ,pgsql ) ইত্যাদি ডাটাবেস এর সাথে সংযোগ স্থাপন করে বিভিন্ন কার্য সম্পাদন করা যায়।

<?php

//////////////////////////////////////////////////////////////
$host = "localhost"; //  Server Name Of Host Location Where Your Database You Can Use Ip Address Like 127.0.0.1  .
$db = "test"; // Put Here Your Database Name Where You Store And Receive Information .
$user = "root"; //Your Server Login User Name
$pass = "usbw"; // Server Login Password by Default "" for Local Pc

$db_type;





class Database
{



    public $charset = "utf8mb4";// Which Unicode Use To Received And Store Data Opreation utf8mb4m give More Freture than utf8
    public $port = 3306; //port number of server
    public $pdo;
   public $options = [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION, 
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        PDO::ATTR_EMULATE_PREPARES   => FALSE,
        PDO::ATTR_PERSISTENT         => true,
    ];

    public function __construct($db_type,$host,$db,$user,$pass)
    {
        
        if (!isset($this->pdo)) {
            if ($db_type == "mysql") {
                $dsn  = "mysql:host=$host;dbname=$db;charset={$this->charset};{$this->charset}";
               try {
                   $this->pdo = new PDO($dsn,$user,$pass,$this->options);
                   echo "connected";
               }
               catch (PDOEXCEPTION $e){
               echo $e->getMessage();
               }
           }
   
   
           elseif ($db_type == "pgsql") {
               $dsn  = "pgsql:host=$host;dbname=$db;charset={$this->charset};{$this->charset}";
               try {
                $this->pdo = new PDO($dsn,$user,$pass,$this->options);
                   //$dsn = "pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password";
   
                   echo "connected";
               }
               catch (PDOEXCEPTION $e){
               echo $e->getMessage();
               }
           }
   
           elseif ($db_type == "sql") {
               $dsn  = "sqlsrv:server=$host;Database=$db;";
               try {
                $this->pdo = new PDO($dsn,$user,$pass);
   //PDO( "sqlsrv:server=$serverName ; Database=AdventureWorks", "", "");
                   echo "connected";
               }
               catch (PDOEXCEPTION $e){
               echo $e->getMessage();
               }
           }
   
        }
  


    }
}


$dbcon = new Database("mysql","localhost","test","root","usbw");
// To Use This Connection First  global $dbv; then use     $stmt = $dbcon->pdo->prepare( $sql);

এই ক্লাসটি ব্যবহার করার নিয়ম নিম্নই দেখানো হলো :
১. যদি আমরা কোনো ডেটাবেসে কানেকশন করতে চাই তাহলে ক্লাসের কনস্ট্রাক্ট মেথডে প্যারামিটার হিসাবে ডাটাবেসের ইনফরমেশন দিলেই ডাটাবেসের সাথে সংযোগ করবে। যেমন $dbcon = new Database(“mysql”,”localhost”,”test”,”root”,”usbw”); তবে প্রথমে কানেকশন ক্লাসকে ইনক্লুড করে নিতে হবে। এই ভ্যারিয়েবল টি echo করলে কানেক্টেড নাম স্ট্রিং প্রদান করবে যেটা কোনো এক জায়গায় শো করে আমরা বুঝতে পারবো যে আমরা সার্ভার এর সাথে সংযুক্ত আছি কিনা যেমন : echo $dbcon ;

২. এই ক্লাসটি বেবহার করে কিভাবে ডাটাবেস অপারেশন করবো ?
কানেকশন ক্লাস এর কানেক্শনটি ব্যবহার করার জন্য সিম্পলি এভাবে বেবহার করবো : $stmt = $dbcon->pdo->prepare( ‘SELECT * FROM users WHERE email = ? AND status=?’); প্যারামিটার হিসাবে আমরা সকল কোয়েরি দেব এবং পরবর্তীতে $stmt কে বেবহার করে কাজ সম্পাদন করবো।

$stmt->execute([$email, $status]);
$user = $stmt->fetch();
// or
$stmt = $pdo->prepare(‘SELECT * FROM users WHERE email = :email AND status=:status’);
$stmt->execute([’email’ => $email, ‘status’ => $status]);
$user = $stmt->fetch();

এখন আমরা দেখবো কিভাবে প্রাক্টিক্যালয় কাজ করা যায়.

PHP Mysql Apache Server Maintanance

  • phpmyadmin Sql Import File Size Increase
Solution :
Open Php ini File And Edit And Restart Server
Find following variables and change values as you need:

post_max_size = 8M  //
upload_max_filesize = 2M  // Sql Import File Size
max_execution_time = 30
max_input_time = 60
memory_limit = 8M


PHP PDO DATA FETCH ARRAY To JSON CONVERT

        $sql = " SELECT * FROM user_accounts ";

        $stmt = $dbcon->pdo->prepare($sql);

         $stmt->execute();
        $data = array();

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $data['alldata'][]= $row;
        }

echo json_encode($data);


PHP PDO BINDPARAM EXAMPLE

bindParam() Hold Five Parameter. PDO bindParam() Use For Prevent Sql Injection And Safe From Malware Hacker Attacker.

first parameter placeholder secend value third value type 4th value length And 5th Is Driver Option. Below The Example. Returns TRUE on success or FALSE on failure.

Example #1 Execute a prepared statement with named placeholders

<?php
/* Execute a prepared statement by binding PHP variables */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < :calories AND colour = :colour');
$sth->bindParam(':calories', $calories, PDO::PARAM_INT);
$sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12);
$sth->execute();
?>

Example #2 Execute a prepared statement with question mark placeholders

<?php
/* Execute a prepared statement by binding PHP variables */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?');
$sth->bindParam(1, $calories, PDO::PARAM_INT);
$sth->bindParam(2, $colour, PDO::PARAM_STR, 12);
$sth->execute();
?>

Example #3

        $sql = "INSERT INTO USER (name,email,password,created) VALUES (?,?,?,NOW())";
        $stmt = $this->conn->prepare($sql);
        $stmt->bindParam(1,$name,PDO::PARAM_STR,25);// first parameter placeholder secend value third value type 4th value length
        $stmt->bindParam(2,$email,PDO::PARAM_STR,12);// first parameter placeholder secend value third value type 4th value length
        $stmt->bindParam(3,$password,PDO::PARAM_STR,12);// first parameter placeholder secend value third value type 4th value length
        $result = $stmt->execute(); // Returns TRUE on success or FALSE on failure.


        $stmt->close();


Example #4

$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
        $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt);
        $result = $stmt->execute();
        $stmt->close();



Example #5

<?php
/* Call a stored procedure with an INOUT parameter */
$colour = 'red';
$sth = $dbh->prepare('CALL puree_fruit(?)');
$sth->bindParam(1, $colour, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 12);
$sth->execute();
print("After pureeing fruit, the colour is: $colour");
?>