today i will show , how to connect database with pdo.
step 1
go to your phpmyadmin and create a new db.
step 2
create a php file in your htdocs folder,like filename.php
step 3
then type the Following code blew.
- <?php
- $host = "localhost";
- $user = "root";
- $pass = "";
- $conn = new pdo ("mysql:host=$host;dbname=mydb,$user, $pass ");
- if($conn==true){
- echo"database connected";
- }
- ?>
explanation of the variable that we have used in our filename.php file:
- $host will be the host where your server is running it is localhost.
- $user will be the username i.e. root and $pass will be the password which is same that you access your phpmyadmin.