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 4033748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:53:09+00:00 2026-05-20T11:53:09+00:00

I am pulling back some data from the twitter query API, and parsing it

  • 0

I am pulling back some data from the twitter query API, and parsing it through PHP like so:

    $i =0;
    foreach ($tweetArray->results as $tweet) {
        $timeStamp = strtotime($tweet->created_at);
        $tweetDateTime = date('m-d-Y H:m:s', $timeStamp);
        if($i > 0){
            $SQL .= ',';
        }
        $SQL .= "(". $tweet->id .",'" . $tweet->from_user ."','". addslashes($tweet->profile_image_url) . "','". addslashes($tweet->text). "','" . $tweetDateTime ."')";
        $i++;
    }
    $SQL .= " ON DUPLICATE KEY UPDATE 1=1";

This leaves me with a SQL statement looking like this:

INSERT 
    INTO 
        tblTwitterSubmit (tweetId, twitterAuthor, authorAvatar, tweetText, tweetDateTime)
    VALUES
    (111,'name','http://url.com','a string of text','03-04-2011 13:03:09'),
    (222,'anothername','http://url.com','another tweet','03-04-2011 12:03:51')
ON DUPLICATE KEY UPDATE 1=1;

I am unfortunately getting the following error: 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 '1=1' at line 1.

Edit:
The 1=1 is supposed to not do anything. The tweets don’t change, and so if I pull the same one back twice for any reason, nothing will happen, but it also won’t throw a duplicate key error.

Re-edit:
The problem appears to have something to do with the key field I was using, which was the id of tweet as assigned by twitter.

I re-factored the code anyway, since it seemed pretty evident that what I had read in articles as a “really-good-idea” wasn’t. I now included a PDO submit inside the for loop so I just make a bunch of submissions instead of one long sql string.

Hopefully this is better practice.

Leaving this open for a couple minutes hoping for some feedback if this is the way to do it or not.

  • 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-05-20T11:53:10+00:00Added an answer on May 20, 2026 at 11:53 am

    Are you sure you’re using the right syntax for on duplicate key update ?

    Judging from it’s manual’s page, it seems you have to specify a column name, and not 1=1.

    From what I understand, if you want to indicate “use the value from the values() clause when there’s a duplicate”, you should use something like this :

    on duplicate key update your_col=values(your_col)
    

    Quoting the relevant part :

    You can use the VALUES(col_name)
    function in the UPDATE clause to
    refer to column values from the
    INSERT portion of the INSERT ... ON
    DUPLICATE KEY UPDATE
    statement.

    In other words,
    VALUES(col_name) in the ON
    DUPLICATE KEY UPDATE
    clause refers to
    the value of col_name that would be
    inserted
    , had no duplicate-key
    conflict occurred.

    This
    function is especially useful in
    multiple-row inserts.

    Then, as a sidenote, you must escape your strings using the function that matches your API — probably mysql_real_escape_string — and not the generic addslashes, which doesn’t know about the specificities of your database engine.

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

Sidebar

Related Questions

I'm pulling back a Date and a Time from a database. They are stored
My code is pulling from a data cells that lists multiple file paths and
I have an odd one - I am porting some data from one CMS
I am pulling a long timestamp from a database, but want to present it
I'm pulling email address records from a table in SQL Server 2005, and want
I am pulling data out of an old-school ActiveX in the form of arrays
I'm pulling a list of items from one table, on the basis of their
I'm pulling a row from a database and there is a date field (y-m-d).
I need to suck data from stdin and create a object. The incoming data
I'm trying to stick some data into the app so I can then build

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.