How To Create Connection In Php-Full Detail In Hindi

Hello friends aaj me apko php and mysql Database me connection bnana sikhaunga
Sabse pehle to jan lijiye ki jo php 5 hai or uske bad ke sare version hai sabhi mysql ke sath do trah se kam kar sakte hai.

·         Mysqli extention( i-yanha I ka matlab improved hai)
·         Pdo(php data object)



Features-dosto me apko btana chahunga ki dono he method kaffi secure hai bas farq sirf itna hai ki       php data object(pdo) 12 alag alag database ko support karta hai matlab agar apne kisi ek database me project bnaya hai or ab aap us project ko kisi dusre database se attach karna chahte hai to pdo is kamm ko bhut easy manage kar leta hai .par mysqli extension sift mysql database ko he support karti hai.pehle mysql ka use kiya jata tha but isme improvement hue or ye mysqli ban gya .php me lagatar implementation hoti rehti hai .Me apko suggest karunga ki aap pdo par work karna sikhe kiunki ane wale samaye me sara work pdo par he hoga.ab aap samjh sakte ho ki
Pdo jyada behtar hai kiunki ye ham alag alag database me apna project switch karne ki functionality provide karta hai



Connection Kese Bnaye-
Yanha connection bnane ki 3 ways hai
·         Mysqli(object –Oriented)
·         Mysqli(procedural)
·         Pdo(php data object)

     MYsqli(Object-Oriented)


 
$servername = 
" Enter localhost";
$username = 
" Enter username";
$password = 
"Enter password";

$conn = 
new mysqli($servername, $username, $password);



if ($conn->connect_error) {
    

die("Connection failed: " . $conn->connect_error);
}
 
echo "Connected successfully";
?>





Mysqli(Procedurral)-


$servername = 
" Enter Your  servername here";
$username = 
" Enter username";
$password = 
" Enter password";


$conn = mysqli_connect($servername, $username, $password);


if (!$conn) {
    
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>

Pdo(Php Data Object)
  

$servername = " Enter your servername here";
$username = 
" Enter Your Username Here";
$password = 
"Enter your password here";try {
    $conn = 
new PDO("mysql:host=$servername;dbname=enter your databasename here", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
echo "Connected successfully"; 
    }
catch(PDOException $e)
    {
    
echo "Connection failed: " . $e->getMessage();
    }
?>







Other features of the Mysqli and pdo

·         Dono prepared statement ko support karte hai prepared statement ka kam hame sql injection se bchana hota hai sql injection ka use hacker karte hai hmare website ko hack karne ke liye but agar hmare coding me prepared statement ka use ho to hacker hmare website ko hack nhi kar pate.
·         Mysqli ke do types hai ek to object oriented or dusre mysqli procedural


To dosto is parkar aap easily php and mysql me connection teyar kar sakte ho 3 different ways se me apko suggest karunga ki aap jyada se jyada pdo ka use karne ki koshish kare kiunki sara work future me pdo me he hoga.
Me ummid karta hu ki apko mere ye post achi lagi hogi agar apko database connection create karne me koi be problem a rhe hai to aap mujse comment me puch sakte hai me apki puri sahyata karne ki koshish karunga
thank you
team gajabwap in Hindi
Also Read-



Previous
Next Post »

1 comments:

Click here for comments
sam thakur
admin
12 April 2018 at 02:00 ×

bhai connection to ban gya ab Age work kese kare

Congrats bro sam thakur you got PERTAMAX...! hehehehe...
Reply
avatar
Thanks for your comment