Welcome Guest, Not a member yet? Register   Sign In
This empty string won't insert in my database
#1

[eluser]jpcody[/eluser]
Forgive me if I could have any sort of fundamental error here. I'd imagine there's something simple I'm missing. I'm looking to store Twitter updates in a database with only a few fields: an auto-increment index, the time posted, the actual status update & the user id the update is in reply to.

I'm simply storing this last field so I can provide a method of filtering out replies.

But it appears that my SQL code is throwing an error. As of this writing, the SQL properly inserts the two most recent updates, which are both replies to another user and, therefore, have data in the in_reply_to_user_id field. But on the third update, which is not in reply to anyone, I get the following errors:

Quote:A PHP Error was encountered

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: database/DB_driver.php

Line Number: 598

and

Quote:Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

INSERT IGNORE INTO updates (time, status, postid, reply) VALUES (1260070319, 'I guess Johnny Cash knew what he was talking about in that \"A Boy Named Suh\" song. That guy is both fast and mean.', '6389320556', )

Twitter's API states no default value for this parameter. I tried the same query with the "favorited" parameter, and it correctly labeled each row with "false" in my database. So I'm assuming my problem is with inserting an empty string.

For what it's worth, here is my CodeIgniter method:

Code:
function insert_tweet($tweet){
        foreach($tweet as $t) {
                $when = strtotime($t->created_at);
                $status = $t->text;
                $postid = $t->id;
        $reply = (is_null($t->in_reply_to_user_id) ? 'NULL' : $t->in_reply_to_user_id);
                $sql = 'INSERT IGNORE INTO updates (time, status, postid, reply) VALUES (?, ?, ?, ?)';
                $this->db->query($sql, array($when, $status, $postid, $reply));
        }
}

Any help you could give would be great! I hope I've provided enough information!

More info:

If it's any help, the content of the empty strings I'm trying to insert is stdClass Object().


Messages In This Thread
This empty string won't insert in my database - by El Forum - 12-06-2009, 12:08 PM
This empty string won't insert in my database - by El Forum - 12-06-2009, 03:32 PM
This empty string won't insert in my database - by El Forum - 12-06-2009, 03:35 PM
This empty string won't insert in my database - by El Forum - 12-06-2009, 04:07 PM
This empty string won't insert in my database - by El Forum - 12-06-2009, 04:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB