Skip to content

Commit 9f698f9

Browse files
Update README.md
1 parent ca3078a commit 9f698f9

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

README.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1-
# connection-of-SQL-database-using-PHP
2-
Database Connectivity using Mysqli and PDO method in PHP
1+
<!-- conection for database using mysqli for local host -->
2+
3+
<?php
4+
5+
$con = mysqli_connect("localhost","root","password","database_name");
6+
7+
?>
8+
9+
<!-- connection by PDO -->
10+
11+
<?php
12+
$user='root';
13+
$pass='';
14+
$dbname='database_name';
15+
16+
$conn = new PDO('mysql:host=localhost;dbname= database_name', $user, $pass);
17+
if (!$conn) {
18+
die("Connection failed: " . $conn->connect_error);
19+
}
20+
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
21+
?>
22+

0 commit comments

Comments
 (0)