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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:18:58+00:00 2026-06-07T14:18:58+00:00

I found this http://net.tutsplus.com/tutorials/php/the-problem-with-phps-prepared-statements/ and it works really good to have it in a

  • 0

I found this http://net.tutsplus.com/tutorials/php/the-problem-with-phps-prepared-statements/

and it works really good to have it in a seperate php file which my other files calls to with a query as argument.

Is it possible to make something similar with other queries like insert and update?

  • 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-07T14:19:01+00:00Added an answer on June 7, 2026 at 2:19 pm

    This is the updated example:

    $params is an array.

     function insertToDB($params, $db) { //Pass array and db
    
            $fields = array();
            $conn = new mysqli('localhost', 'root', 'root', 'db') or die('XXX');     
            $stmt =  $conn->stmt_init();
            $stmt->prepare("SELECT * FROM ".$db); 
            $stmt->execute();
            $meta =  $stmt->result_metadata();
            while ($field = $meta->fetch_field()) { 
                 $fields[] = $field->name;   
            }
    
            $fields = implode(", ", $fields);
    
    
            $placeholders = implode(',', array_fill(0, count($params), '?'));
    
            $types = '';
            foreach($params as $value) {
                $types.= substr(strtolower(gettype($value)), 0, 1); 
            }
    
            $ins = "INSERT INTO MYDB (".$fields.") VALUES (".$placeholders.")"; 
    
            $bind_names[] = $types; 
            for ($i = 0; $i < count($params); $i++) { 
                $bind_name = 'bind' . $i;
                $$bind_name = $params[$i];
                $bind_names[] = &$$bind_name;
            }
            if ($stmt->prepare($ins)) {
                    call_user_func_array(array($stmt,'bind_param'),$bind_names); 
                    $insresult = $stmt->execute(); 
            }
            return $insresult;
            $stmt->close();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this tutorial online http://net.tutsplus.com/tutorials/php/creating-a-php5-framework-part-1/ I have created myself a simple sort
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
I'm following this tutorial and am trying to modify it to my use: http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-butt-css3-mega-drop-down-menu/
I'm referencing the jQuery autocomplete plugin code seen in this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/how-to-use-the-jquery-ui-autocomplete-widget/ The problem
I found this on net in google search and see article here: http://www.thatcssguy.com/limit-your-divs/ See
I'm running through this tutorial found here: http://vb.net-informations.com/crystal-report/vb.net_crystal_report_from_multiple_tables.htm which teaches how to pass a
I've found this at connection strings.com http://connectionstrings.com/mysql Do I need to download connector-net from
I followed the HTML5 Websocket tutorial of the website below: http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ It worked well,
Possible Duplicate: Does PHP have threading? I found this: http://php.net/manual/en/function.pcntl-fork.php But I can't tell
I found this at http://www.php.net/manual/en/regexp.reference.subpatterns.php (?|(Sat)ur|(Sun))day this mean (Sat) and Sun will be matched

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.