TomLi
TomLi

Reputation: 133

How to pass value in PDO prepare

$stmt = $dbh->prepare('INSERT INTO articles (author, subject, text, date, 
special) VALUES (:author, :subject, :text, :date, :special)');

How should it look like when i need to add "special" value to database but "date is automatic and i dont need it in prepare statement.

Upvotes: 0

Views: 39

Answers (3)

Dinesh Belkare
Dinesh Belkare

Reputation: 631

Make Your statement by omitting date

$stmt = $dbh->prepare('INSERT INTO articles (author, subject, text,  
special) VALUES (:author, :subject, :text, :special)');

AND in database make date with type TIMESTAMP and default value = "CURRENT_TIMESTAMP".

Upvotes: 1

ThinkTank
ThinkTank

Reputation: 1191

An other option is to make date with type TIMESTAMP and default value = "CURRENT_TIMESTAMP".

Consequently the database will do the work itself.

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157839

Well, just omit it

$stmt = $dbh->prepare('INSERT INTO articles (author, subject, text,  
special) VALUES (:author, :subject, :text, :special)');

That's SQL syntax that has nothing to do with PDO and prepared statements.

If you don't want to prepare some value - just don't prepare it. That's all

Upvotes: 2

Related Questions