Home  >  Q&A  >  body text

I have been unsuccessful in running prepared statements in PDO. I would like to ask some experts to give me some advice.

<?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "myDBPDO";


try{

$conn = new PDO("mysqli:host=$servername;dbname=$dbname; ",$username,$password);


## //Set the PDO error mode to exception

$conn->serAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


//Preprocess SQL and bind parameters

$stmt= $conn->prepare("INSERT INTO MyGuests (firstname,lastname,email) VALUES(:firstname,:lastname,:email)");


$stmt->bindParam(':firstname',$firstname );

$stmt->bindParam(':lastname',$lastname);

$stmt->bindParam(':email',$email);


                            //                                                                                                       out’s               out’s           ’‐ ‐     ‐ ‐ ‐ ‐‐ ‐ ‐ ‐ ‐ ‐                                                                                 -            $email = "jhon@example.com";

$stmt->execute();

## $firstname = "Mary";

$lastname = "Moe";

$email = "mary@example.com";


$stmt->execute();

      $firstname = "Julie";

        $lastname = "Dooley";

        $email = "julie@example.com";


        $stmt->execute();

##                                                       $stmt->execute();

##                                                                       using  --                     $stmt->execute(); ";


## }catch(PDOException $e){

echo "Error:<br> ". $e->getMessage();


}

## $conn=null;

 

?> ;

WW2496 days ago905

reply all(1)I'll reply

  • 电动小老虎

    电动小老虎2017-11-23 23:05:09

    Post the error code, otherwise you won’t be able to read it. .

    reply
    0
  • Cancelreply