1

I have read that PHP is obsoleting the MySql functions.

How will we connect to MySql database?

4 Answers 4

4

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')

Sign up to request clarification or add additional context in comments.

2 Comments

It was supposed to be deprecated, it was even in the manual, but they must have reversed that decision because i dont see any mention of it anymore.
Thanks for the link @seriousdev. That's great news. Yeah, the mysql extension is used so widely there's no way they could really deprecate it or throw notices. But it's appropriate to encourage people to use the more feature-rich extensions.
1

Using the new MySQLi classes.

Comments

1

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.

Comments

1

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();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.