How to make database connection in php?
Answer / Mahesh Chauhan
To connect to a database in PHP, you can use the PDO (PHP Data Objects) library. Here is an example:nn<?php try {n $db = new PDO('mysql:host=localhost;dbname=testdb', 'username', 'password');n $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);n echo 'Connected successfully';n} catch(PDOException $e) {necho 'Connection failed: ' . $e->getMessage();n}n?>
| Is This Answer Correct ? | 0 Yes | 0 No |
What is empty php?
Is array function in php?
What is session data?
Explain a resource?
Explain the types of functions for Splitting String?
Is session a cookie?
Is php 5 still supported?
Where are php configuration settings stored?
What is difference between $x and $$x
5 Answers Mindex, Net Solution, Procon IT Solutions, Trigent,
What is difference Between PHP 5 and 7?
How cookies are transported from browsers to servers?
How is a constant defined in a PHP script?