Jump to content

Trying to use PDO insert with now()


nakins

Recommended Posts

I'm trying to use PDO and get used to doing things this way. I've been away from php/mysql for a few years, so, I'm crusty.  I'm not getting any error messages back on this code, but the insert just doesn't happen.  My first guess is that I'm doing something wrong with the datetime now() function.  But, I may not have the PDO code right. I tried the script the old fashion way with mysql_query() and that worked.  So, it has to be something in this code. I believe my server is set up to do PDO as it shows:

PDO

PDO support enabled

PDO drivers mysql, sqlite

 

pdo_mysql

PDO Driver for MySQL, client library version 5.0.45

 

My php version is 5.2.14 and Mysql is 5.0.45.

 

Any help would be appreciated.

 

     $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
     $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

     $sql=$DBH->prepare("INSERT INTO assets(asset_name,date_added,short_desc) VALUES (:asset_name,NOW(),:short_desc)");

     $sql->bindParam(':asset_name',$asset_name);
     $sql->bindParam(':short_desc',$short_desc);

     $name=$_POST["input1"];
     $short_desc=$_POST["input2"];

     $DBH->exec();
     echo $name;

    echo "\nPDO::errorInfo():\n";
    print_r($DBH->errorInfo());
   }
   catch(PDOException $e) {
     echo "Syntax Error: ".$e->getMessage();
   }

Link to comment
https://forums.phpfreaks.com/topic/219399-trying-to-use-pdo-insert-with-now/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.