FIXED!
The problem was I didn’t know you had to initialize a connection to PDO separate from a normal connection:
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
I’m trying to learn PDO for security purposes + just good practices. Is this correct on how I would translate an insert query into PDO? It doesn’t seem to be working. $dbh has to be my connection to the server correct?
$stmt = $dbh->prepare("INSERT INTO users (social_id, name, email, social_network, profile_pic) VALUES (:social_id, :name, :email, :social_network, :profile_pic)");
$stmt->bindParam(':social_id', $social_id);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':social_network', $social_network);
$stmt->bindParam(':profile_pic', $profile_pic);
// insert one row
$stmt->execute();
$user_id = $dbh->lastInsertId();
From this:
mysql_query("INSERT INTO users (social_id, name, email, social_network, profile_pic)
VALUES ('$social_id', '$name','$email', '$social_network','$profile_pic')");
$user_id = mysql_insert_id();
The problem was I didn’t know you had to initialize a connection to PDO separate from a normal connection: