Twitter bot coding fail: is my MySql setup right?
-
I have been trying and failing, to code a twitter bot that tweets lines held in a MYSQL database, one by one, in order. I have a DATABASE with two tables: 1. tweetstable - holds a lot of tweets (tweetsfield) and an id column (id) 2. last_row - holds a single number, updated each tweet with the id of last tweeted line I must warn you that this was pasted together from various sources and is probably riddled with errors, or missing entire sections. I am not a coder, I hack stuff together and eventually get stuff working. This time I am WAAAY over my head. The following code should select the id of the last tweeted line: $last_id = $last_row->id; Then selects the a line from the text table that is greater than then $last_id and is not blank: $db2->where('id >',$last_id); $db2->where('tweetsfield !='," "); Then tweets the line, and stores the id of the line back in the database... But it fails miserably. I'm getting this error Fatal error: Call to a member function where() on a non-object in /LOCATION/index.php on line 13 i.e. $db2->where('id >',$last_id); Even if I define $db at start as $db2 What am I missing? <?php /* database parameters */ $db_host = 'HOST'; $db_user = 'USERNAME'; $db_pw = 'PASSWORD'; $db = 'DATABASE'; mysql_connect($db_host, $db_user, $db_pw) or die('Could not connect to database'); mysql_select_db($db) or die('Could not select database'); $last_id = $last_row->id; $db2->where('id >',$last_id); $db2->where('tweetfield !='," "); $new_last_id = $line->id; $db2->set('id',$new_last_id); $db2->update('last_row'); function tweetline() { $config = array( 'CONSUMER_KEY' => CONSUMER_KEY, 'CONSUMER_SECRET' => CONSUMER_SECRET, 'ACCESS_TOKEN' => ACCESS_TOKEN, 'ACCESS_TOKEN_SECRET' => ACCESS_TOKEN_SECRET ); $this->load->library('TwitterOAuth',$config); $twitter = new TwitterOAuth($config); $db2 = $this->load->database('DATABASE', TRUE); $last_row = $db2->get('last_row'); $last_row = $last_row->row(); $last_id = $last_row->id; $db2->where('id >',$last_id); $db2->where('tweetfield !='," "); $db2->limit(1); $aline = $db2->get('tweetstable'); if ($aline->num_rows() > 0) { $line= $aline->row(); $tweet = $line->tweetfield; // tweet the tweet $twitter->post('statuses/update',array('status' => $tweet)); sleep(1); $db2 = $this->load->database('last_row', TRUE); $new_last_id = $line->id; $db2->set('id',$new_last_id); $db2->update('last_row'); die(); } } ?>
-
Answer:
Fatal error: Call to a member function where() on a non-object in /LOCATION/index.php on line 13 means that $db2 is not an object. $db2 is a string. it contains the word "DATABASE". (if you define $db at start as $db2. If you don't, then $db is undefined!). So yeah, your MySQL setup is definitely not right!
Adam Marshall at Quora Visit the source
Related Q & A:
- In what ways can we distinguish between a human and bot behavior?Best solution by researchgate.net
- What are the consequences of adopting a pass or fail grading system?Best solution by Yahoo! Answers
- How do I get mail in my in-box without the right address or right name?Best solution by Yahoo! Answers
- Does anyone know how banks fail?Best solution by Yahoo! Answers
- Why do photos fail to upload on e-bay?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.