Reputation: 23
I have read that PHP is obsoleting the MySql functions.
How will we connect to MySql database?
Upvotes: 1
Views: 111
Reputation: 562951
Where did you hear that? I think it would be a great idea, but it's news to me.
It's better to use new mysqli('hostname', 'username', 'password', 'database')
Or (even better) use new PDO('mysql:dbname=database;host=hostname', 'username', 'password')
Upvotes: 4
Reputation: 11693
Using PDO (PHP Data Objects)
example.
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
Upvotes: 1
Reputation: 47776
The new, better way of doing it is to use PDO. You can find pretty of examples on the web if you Google for "php mysql pdo", here is one.
Upvotes: 1