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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.