Re: SqLite INSERT want not write

From: Date: Thu, 19 Apr 2012 19:36:15 +0000
Subject: Re: SqLite INSERT want not write
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-317632@lists.php.net to get a copy of this message
On Thu, Apr 19, 2012 at 2:17 PM, Steven Staples <sstaples@mnsi.net> wrote: >> -----Original Message----- >> From: Silvio Siefke [mailto:siefke_listen@web.de] >> Sent: April 19, 2012 3:11 PM >> To: php-general@lists.php.net >> Subject: Re: [PHP] SqLite INSERT want not write >> >> On Thu, 19 Apr 2012 14:57:04 -0400 >> "Steven Staples" <sstaples@mnsi.net> wrote: >> >> > I think all you had to do was change this line: (line 27 in the >> > original >> > paste) >> > $sql = 'INSERT INTO bloggen (date, autor, title, teaser, content) >> >       VALUES ('' . date( 'Y-m-s H:i:s', time() ) . >> > '', :autor, :title, >> > :teaser, :content);'; >> > >> > To this: >> > $sql = "INSERT INTO bloggen (date, autor, title, teaser, content) >> >       VALUES ('' . date( 'Y-m-s H:i:s', time() ) . >> > '', :autor, :title, >> > :teaser, :content);"; >> >> Thats end with: >> PDOException: SQLSTATE[HY000]: General error: 1 near "(": syntax error >> >> I has changed what say Stuart, no Sytax errors but in the database nothing >> will write. >> >> Regards >> Silvio >> > > Ok, so I was wrong... ;)   it does happen > > Try this: > $sql = "INSERT INTO bloggen (date, autor, title, teaser, content) >       VALUES ('" . date('Y-m-d H:i:s') . "', :autor, :title, >  :teaser, :content);"; > > Or > $sql = "INSERT INTO bloggen (date, autor, title, teaser, content) >       VALUES (NOW(), :autor, :title, :teaser, :content);"; > > > The first example, you don't need the time(), and you had the date format > wrong... > The second example, uses the NOW() time, which is the timestamp for sql > > Maybe this time I will get it right ;) -- its been a long day, and it is > only 1/2 done > > Steve > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > For sqlite, you can specify the current datetime with just "now". So perhaps the insert statement could be simplified to: $sql = "INSERT INTO bloggen (date, autor, title, teaser, content) VALUES(now, :autor, :title, :teaser, :content);";

« previous php.general (#317632) next »