PDO MYSQL PHP prepare() and execute()

421 Views Asked by At

its not linking up to the database. I've been trying to use prepare() and execute() to get it to post on the database but nothing shows up what am I doing wrong?

<?php
    try {
        $dbh = new PDO('mysql:host=localhost;dbname=phpexample', 'root', '');
    }
    catch (PDOException $e) 
    {
        echo "Connection error: " . $e->getMessage();
    }

    $query ="INSERT INTO products (id, sku, name) VALUES (:id, :sku, :title)";
    $stmt = $dbh->prepare($query);

    $id = NULL;
    $sku = 'MN873213';
    $title = 'Minty Mouthwash';

    //binding parameters
    $stmt->bindParam(':id', $id);
    $stmt->bindValue(':sku', $sku);
    $stmt->bindValue(':title', $title);

    //execute the query
    $stmt->execute();
?>
0

There are 0 best solutions below