· 7 years ago · Oct 24, 2017, 08:12 AM
1<?php
2 $servername = "192.168.1.12";
3 $username = "root";
4 $password = "root";
5
6 try {
7 $conn = new PDO("mysql:host=$servername;dbname=my_db", $username, $password);
8 // set the PDO error mode to exception
9 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
10 echo "Connected successfully";
11 }
12 catch(PDOException $e)
13 {
14 echo "Connection failed: " . $e->getMessage();
15 }
16?>