PHP PDO problem

I’m a little inexperienced back side, I was trying to create a small booking form with php and DOP connection but I always get an error for the prepar () property. esegundo of var_dump () on the connection I have seen that it returns this answer … to give you a hand I tell you that I have already de-flagged the PDO extension in the php.ini file and that I use a LAMP stack on Ubuntu machine. I have no idea how to move, could some good person help me understand where I’m wrong and put me on the solution and make me understand where is my mistake?

place my code for clarity, and thank anyone who wants to log in

Code:

<?php
try{
  /*Connection file db.php */
  $dsn = "mysql:host=localhost;dbName=lamp";
  $conn = new PDO($dsn, "root", "StraMa87");
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  echo "connessione avvenuta con successo";
}catch(PDOException $e){
$e->getMessage();
}
?>

This is the class file that manages the reservation:

<?php
/**
 *  Booking
 */
class Booking
{
  public $db;
  function __construct($db)
  {
    var_dump($db);
    $this->db = $db;
  }
  public function booking_table($post){
$nome = trim($post["nome"]);
$email = filter_var( filter_var( trim( $post["email"] ), FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL );
$tel = trim( $post["tel"] );
$intolleranze = trim($post["intolleranza"]);
$data = trim($post["date"]);
$hour = trim($post["hour"]);
/* Query  */
$q = "INSERT INTO booking (nome,telefono,email,intolleranze,data_prenotazione,hour) VALUES ('$nome', '$tel', '$email', '$intolleranze', '$data', '$hour')";
try {
  $rq = $this->db->prepare($q,  array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
  $rq->bindParam(':nome', $nome, PDO::PARAM_STR);
  $rq->bindParam(':tel', $tel, PDO::PARAM_STR);
  $rq->bindParam(':email', $email, PDO::PARAM_STR);
  $rq->bindParam(':intolleranze', $intolleranze, PDO::PARAM_STR);
  $rq->bindParam(':data', $data, PDO::PARAM_STR);
  $rq->bindParam(':hour', $hour, PDO::PARAM_STR);
  $rq->execute();
} catch (PDOException $e) {
  $e->getMessage();
}

  }
}

This is the form that must send the data (the html is not made by me, because my purpose was to practice on the php and the back end side):

<?php
require_once('./booking/db.php');
require_once('./booking/booking.php');
ini_set('display_error', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 $booking = new Booking($conn);
if( $_POST ){
  $booking->booking_table($_POST);
}
 ?>
<!DOCTYPE html>
 <html lang="en">
   <head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 <meta name="description" content="">
 <meta name="author" content="">
 <title>Business Casual - Start Bootstrap Theme</title>
 <!-- Bootstrap core CSS -->
 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
 <!-- Custom fonts for this template -->
 <link href="https://fonts.googleapis.com/css?family=Raleway:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
 <link href="https://fonts.googleapis.com/css?family=Lora:400,400i,700,700i" rel="stylesheet">
 <!-- Custom styles for this template -->
 <link href="assets/css/master.css" rel="stylesheet">
  </head>
   <body>
 <h1 class="site-heading text-center text-white d-none d-lg-block">
   <span class="site-heading-upper text-primary mb-3">A Free Bootstrap 4 Business Theme</span>
   <span class="site-heading-lower">Business Casual</span>
 </h1>
 <!-- Navigation -->
 <nav class="navbar navbar-expand-lg navbar-dark py-lg-4" id="mainNav">
   <div class="container">
     <a class="navbar-brand text-uppercase text-expanded font-weight-bold d-lg-none" href="#">Start Bootstrap</a>
     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
       <span class="navbar-toggler-icon"></span>
     </button>
     <div class="collapse navbar-collapse" id="navbarResponsive">
       <ul class="navbar-nav mx-auto">
         <li class="nav-item px-lg-4">
           <a class="nav-link text-uppercase text-expanded" href="index.php">Home
             <span class="sr-only">(current)</span>
           </a>
         </li>
         <li class="nav-item px-lg-4">
           <a class="nav-link text-uppercase text-expanded" href="about.php">About</a>
         </li>
         <li class="nav-item px-lg-4">
           <a class="nav-link text-uppercase text-expanded" href="products.php">Products</a>
         </li>
         <li class="nav-item px-lg-4">
           <a class="nav-link text-uppercase text-expanded" href="store.php">Store</a>
         </li>
       </ul>
     </div>
   </div>
 </nav>
 <section class="page-section cta">
   <div class="container">
     <div class="row">
       <div class="col-xl-9 mx-auto">
         <div class="cta-inner text-center rounded">
           <h2 class="section-heading mb-5">
             <span class="section-heading-upper">Prenota con noi</span>
             <span class="section-heading-lower">siamo aperti</span>
           </h2>
           <form class="" id='booking' action="<?php $_SERVER["PHP_SELF"]; ?>" method="post">
             <div class="row">
               <div class="form-group col-4">
                 <label for="name">Nome</label>
                 <input type="text" class="form-control" name="nome" id="name" required>
               </div>

               <div class="form-group col-4">
                 <label for="tel">Telefono</label>
                 <input type="tel" class="form-control" name="tel" id="tel" required>
               </div>

               <div class="form-group col-4">
                 <label for="email">Email</label>
                 <input type="email" class="form-control" name="email" id="email" required>
               </div>

               <div class="form-group col-4">
                 <label for="intolleranza">Intolleranze</label>
                 <select class="custom-select" required name="intolleranza" id="intolleranza">
                   <option selected>Problemi da dichiarare</option>
                   <option value='nessuno'>Nessuno</option>
                   <option value="celiachia">Celiachia</option>
                   <option value="Intolleranza">Intolleranza</option>
                   <option value="3">Allergia</option>
                 </select>
               </div>


               <div class="form-group col-4">
                 <label for="email">Data di prenotazione</label>
                 <input type="date" class="form-control" name="date" id="date" required>
               </div>

               <div class="form-group col-4">
                 <label for="hour">Orario</label>
                 <input type="time" class="form-control" name="hour" id="hour" required>
               </div>

               <div class="form-group col">
                 <button class="btn btn-primary mt-3" type="submit" name="submit" id='submit'>Prenota</button>
               </div>

             </div> <!-- row -->





           </form>
           <p class="address my-5">
             <em>
               <strong>1116 Orchard Street</strong>
               <br>
               Golden Valley, Minnesota
             </em>
           </p>
           <p class="mb-0">
             <small>
               <em>Call Anytime</em>
             </small>
             <br>
             (317) 585-8468
           </p>
         </div>
       </div>
     </div>
   </div>
 </section>

 <section class="page-section about-heading">
   <div class="container">
     <img class="img-fluid rounded about-heading-img mb-3 mb-lg-0" src="img/about.jpg" alt="">
     <div class="about-heading-content">
       <div class="row">
         <div class="col-xl-9 col-lg-10 mx-auto">
           <div class="bg-faded rounded p-5">
             <h2 class="section-heading mb-4">
               <span class="section-heading-upper">Strong Coffee, Strong Roots</span>
               <span class="section-heading-lower">About Our Cafe</span>
             </h2>
             <p>Founded in 1987 by the Hernandez brothers, our establishment has been serving up rich coffee sourced from artisan farmers in various regions of South and Central America. We are dedicated to travelling the world, finding the best coffee, and bringing back to you here in our cafe.</p>
             <p class="mb-0">We guarantee that you will fall in
               <em>lust</em>
               with our decadent blends the moment you walk inside until you finish your last sip. Join us for your daily routine, an outing with friends, or simply just to enjoy some alone time.</p>
           </div>
         </div>
       </div>
     </div>
   </div>
 </section>

 <footer class="footer text-faded text-center py-5">
   <div class="container">
     <p class="m-0 small">Copyright &copy; Your Website 2018</p>
   </div>
 </footer>

 <!-- Bootstrap core JavaScript -->
 <!-- <script src="vendor/jquery/jquery.min.js"></script>
 <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script> -->
  </body>
 </html>

I think you need execute query with database name . you are using following query to insert data :

$q = "INSERT INTO booking (nome,telefono,email,intolleranze,data_prenotazione,hour) VALUES ('$nome', '$tel', '$email', '$intolleranze', '$data', '$hour')";

instead of using the above query use the following query with database name i.e.

$q = "INSERT INTO lamp.booking (nome,telefono,email,intolleranze,data_prenotazione,hour) VALUES ('$nome', '$tel', '$email', '$intolleranze', '$data', '$hour')";

where lamp is the database name you created.
when I run your code with above trick it is inserting data correctly in database.Hope this will help.