Mat
Mat

Reputation: 6324

Transition from mysql to PDO

I'm in the process to learn PDO. I started changing my database connection from this:

$dbname = "database1";


mysql_connect(
  ':/Applications/MAMP/tmp/mysql/mysql.sock',
 'root',
 'root'
) or die( mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());

to PDO connection:

$username = "root";
$password = "root";


try {
$conn = new PDO('mysql:host=localhost;dbname=database1', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}

the connection seems to be working but when I try to login on the website (localhost) it doesn't find my username and password.

  1. Do I need to change all my mysql_query to PDO since I changed the database connection to PDO?
  2. Can I please ask you some reference for a good tutorial to help me during this transition phase? thanks

Upvotes: 0

Views: 1532

Answers (1)

peterm
peterm

Reputation: 92845

  1. Yes you do.
  2. Here is a good PDO tutorial and this one

Upvotes: 3

Related Questions