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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:48:36+00:00 2026-06-17T00:48:36+00:00

Suppose I have a very large array of information for a user: $user=array( name=>john,

  • 0

Suppose I have a very large array of information for a user:

$user=array(
"name"=>"john",
"ip"=>"xx.xx.xx.xx",
"email"=>"john@something.com",
//lots more values
)

Let’s also suppose that this information needs to go into more than one table. For instance a username needs to go table users, address needs to go into a details table, etc.

Now, I use a certain self-made function to insert into my tables that matches array keys to column names and array values to the values being inputted. Something similar to this:

function insert_sql($table, arr $values){
    GLOBAL $dbc;
    $sql="INSERT INTO `$table` (".implode(array_keys($values), ", ").") VALUES (".implode(array_values($values), ", ").")";
    $dbc->prepare($sql)->execute();
    return $dbc->lastInsertId();

}
//I don't actually use this function, just trying to show you what is being accomplished.

The problem is that my function uses all the keys and all the values, so when I just need certain parts of the array put into multiple tables, it doesn’t work.

The question is:

How do I make an INSERT statement ignore a column if it doesn’t exist? So if I insert name,email,address, into table users, but this table doesn’t have an address column, I need it to insert the row with the name and email but simply ignore the fact that the address column is not there.

EDIT: The other option is to make an array with the columns of a table and use it to filter the values array. Although I am not really sure how to set this up.

  • 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-17T00:48:37+00:00Added an answer on June 17, 2026 at 12:48 am

    Find given table column names:

    SELECT 
    column_name
    FROM 
    information_schema.columns
    WHERE 
    table_name =  'tablename'
    

    And then just whitelist your keys in $values array

    Example:

    function insert_sql($table, array $values){
            global $connection;
            $query = "SELECT column_name FROM information_schema.columns WHERE table_name =  :tablename";
            /* @var $stmt PDOStatement */
            $stmt  = $connection->prepare($query);
            $stmt->execute(array(
                'tablename' => $table
            ));
            $columns = array_flip($stmt->fetchAll(PDO::FETCH_COLUMN, 0));
            $values  = array_intersect_key($values, $columns);
            var_dump($values);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a very large site like amazon.com. I’d like to use asp.net
I have a very large structure array in matlab. Suppose, for argument's sake, to
I have a very large list Suppose I do that (yeah, I know the
Suppose, I have very large foreach loop. I want put this loop into try
Suppose, I have a very large std::map< unsigned int, Foo > FooDB , which
Suppose I'm using the MATLAB IDE and happen to have some very large objects
Suppose we have a table which holds information about person. Columns like NAME or
Problem Suppose I have a large array of bytes (think up to 4GB) containing
Suppose I have a large list of words. For an example: >>> with open('/usr/share/dict/words')
Suppose we have the name written in any none-latin letters - languages, like Arabic,

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.