This question already has an answer here:
- How can I get useful error messages in PHP? 26 answers
- How to squeeze error message out of PDO? 4 answers
I am trying to connect with my SQL database using PDO but I am unable to insert the record. I am using prepare statement with named place holder. Please correct me where I am going wrong.
$host = 'localhost';
$username = 'root';
$pass = '';
$db = 'db_pdo';
$dsn = "mysql:host=$host;dbname=$db";
$pdo = new PDO($dsn, $username, $pass);
$sql = "INSER INTO user (user_name, user_phone, user_email, user_city) VALUES (:user_name, :user_phone, :user_email, :user_city)";
$statement = $pdo->prepare($sql);
$statement->bindParam( ':user_name', $user_name );
$statement->bindParam( ':user_phone', $user_phone );
$statement->bindParam( ':user_email', $use_email );
$statement->bindParam( ':user_city', $user_city );
$user_name = 'Test user';
$user_phone = '9998887770';
$use_email = 'test@mailinator.com';
$user_city = 'Test city';
$statement->execute();
echo $statement->rowCount();
</div>