Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:08:24+00:00 2026-06-08T12:08:24+00:00

The code: #!/usr/bin/php <?php error_reporting(E_ALL); while(true){ // Check how many API calls remain $rate_limit

  • 0

The code:

#!/usr/bin/php
<?php
error_reporting(E_ALL);
while(true){
    // Check how many API calls remain
    $rate_limit = json_decode(file_get_contents('http://api.twitter.com/1/account/rate_limit_status.json'),true);
    // Array containing all the Twitter handles
    $handles = array('le4ky');

    if($rate_limit['remaining_hits']<count($handles)){
        file_put_contents('tweet_gremlin.log', date('r') . ' Rate limit reached');
        sleep(30);
    }else{
        // Establish the database connection
        if(!$mysqli = mysqli_connect('localhost','twitterd','password','twitterd')){
            die('Cannot connect to database');
            file_put_contents('tweet_gremlin.log', date('r') . ' Cannot connect to the database');
        }


        // This is the big one.  Loop through the $handles values, make an API call, and insert the tweets.
        foreach($handles as $value){
            // Get the handle's timeline and put it into $user_data
            $user_data = json_decode(file_get_contents('http://search.twitter.com/search.json?q=from:' . $value . '&rpp=100'),true);
            // Put only the results index (tweets) into into $user_data
            $user_data = $user_data['results'];

            for($i=0;$i<count($user_data);$i++){

                // Lazy method for sanitizing variables
                $id = mysqli_real_escape_string($mysqli,$user_data[$i]['id']);
                $created_at = mysqli_real_escape_string($mysqli,$user_data[$i]['created_at']);
                $from_user_id = mysqli_real_escape_string($mysqli,$user_data[$i]['from_user_id']);
                $profile_image_url = mysqli_real_escape_string($mysqli,$user_data[$i]['profile_image_url']);
                $from_user = mysqli_real_escape_string($mysqli,$user_data[$i]['from_user']);
                $from_user_name = mysqli_real_escape_string($mysqli,$user_data[$i]['from_user_name']);
                $text = mysqli_real_escape_string($mysqli,$user_data[$i]['text']);

                $insert_tweets = "INSERT INTO tweets ('id','created_at','from_user_id','profile_image','from_user','from_user_name',`text`) VALUES ({$id},{$created_at},{$from_user_id},{$profile_image_url},{$from_user},{$from_user_name},{$text});";
                $result = mysqli_query($mysqli,$insert_tweets);
            }
        }
        sleep(30);
    }
}
?>

This is basically just meant to be a “daemon” of sorts that retrieves data and inserts it into the database. For the life of me, I can’t figure out why the data isn’t being inserted into the database. The twitterd user has select and insert permissions on the database and can connect from any host.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:08:25+00:00Added an answer on June 8, 2026 at 12:08 pm

    You need quotes around string values in your SQL query:

    $insert_tweets = "
        INSERT INTO tweets
            (`id`,`created_at`,`from_user_id`,`profile_image`,`from_user`,`from_user_name`,`text`) 
        VALUES  
            ('{$id}','{$created_at}','{$from_user_id}','{$profile_image_url}','{$from_user}','{$from_user_name}','{$text}')
    ";
    

    I added them to all values, you can remove them on values you know are numeric (and validated with intval(), floatval() or some other numeric validation function).

    I also replaced single quotes with backticks in your column names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Code: #!/usr/bin/php -q <?php while(true){ $rate_limit = json_decode(file_get_contents('http://api.twitter.com/1/account/rate_limit_status.json'),true); # Check how many API
$escaped_check = escapeshellcmd(/usr/bin/php -f /opt/status/check.php . $_SERVER['REMOTE_ADDR'] . >> /dev/null 2>&1 &); shell_exec($escaped_check); I
The code #!/usr/bin/awk # Sed and AWK by O'Reilly (p.179) # Example of what
My code: #!/usr/bin/env python def Runaaall(aaa): Objects9(1.0, 2.0) def Objects9(aaa1, aaa2): If aaa2 !=
my views.py file code: #!/usr/bin/python from django.template import loader, RequestContext from django.http import HttpResponse
I have the following code #!/usr/bin/perl use Tie::File; tie my @last_id, 'Tie::File', 'last_id.txt' or
I have the following code: #!/usr/bin/ruby class Person def self.speak p = self.new puts
Given the following code #!/usr/bin/perl use Data::Dumper; my %hash; my @colos = qw(ac4 ch1
Here is my code #!usr/bin/env perl # Setup includes use strict; use XML::RSS; use
This code triggers the complaint below: #!/usr/bin/perl use strict; use warnings; my $s =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.