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

  • Home
  • SEARCH
  • 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 6969595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:36:04+00:00 2026-05-27T16:36:04+00:00

EDIT: after discussing here click here i decided to use Francis Avila solution, it

  • 0

EDIT: after discussing here click here i decided to use Francis Avila solution, it is securer, but I didn’t find a way to exploit my way, only everybody says its security risk to use eval(). If you find a way, to exploit my way, please post a comment. :-), so that i understand it and also another users, who use eval 🙂

One more thing not to use eval(), it is slower, for what i wanted todo.

EDIT:

One positive thing, also is in Francis Avila solution is, you need only specific only 2 vars, $SQL + $INPUT, no need more brother with $output.

EDIT: removed the old question and replaced it with this, so you have maybe a better idea what i want to do.

i found a solution how to make a dynamic number of Variables, but its not the optimal solution. Cause i need to edit / add more lines, if the number of variables gets higher than 8. So is there a way, to make that dynamic on dont relay on the switch function

public function readDB($readdb, $input, $output1) {

    $sql = $readdb;
    $stmt = $this->mysqli->prepare($sql);
    if(!empty($input) && is_array($input)) {
        $inputn = count($input);

        switch($inputn) {
            case "1":
                $stmt->bind_param('s', $input[0][0]);
                break;
            case "2":
                $stmt->bind_param('ss', $input[0][0], $input[1][0]);
                break;
            case "3":
                $stmt->bind_param('sss', $input[0][0], $input[1][0], $input[3][0]);
                break;
            case "4":
                $stmt->bind_param('ssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0]);
                break;
            case "5":
                $stmt->bind_param('sssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0]);
                break;
            case "6":
                $stmt->bind_param('ssssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0], $input[6][0]);
                break;
            case "7":
                $stmt->bind_param('sssssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0], $input[6][0], $input[7][0]);
                break;  
            case "8":
                $stmt->bind_param('ssssssss', $input[0][0], $input[1][0], $input[3][0], $input[4][0], $input[5][0], $input[6][0], $input[7][0], $input[8][0]);
                break;
            default:
                break;
        }
    }
    if (!$stmt) {throw new Exception($mysqli->error);}
    $stmt->execute();
    $stmt->store_result();
    $checker = $stmt->num_rows;
    if($checker !== 0) {
        if(!empty($output1)) {
            switch($output1) {
                case "1":
                    $stmt->bind_result($output[0]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0]);
                    }
                    break;
                case "2":
                    $stmt->bind_result($output[0], $output[1]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0], $output[1]);
                    }
                    break;
                case "3":
                    $stmt->bind_result($output[0], $output[1], $output[2]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0], $output[1], $output[2]);
                    }
                    break;
                case "4":
                    $stmt->bind_result($output[0], $output[1], $output[2], $output[3]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0], $output[1], $output[2], $output[3]);
                    }
                    break;
                case "5":
                    $stmt->bind_result($output[0], $output[1], $output[2], $output[3], $output[4]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4]);
                    }
                    break;
                case "6":
                    $stmt->bind_result($output[0], $output[1], $output[2], $output[3], $output[4], $output[5]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4], $output[5]);
                    }
                    break;
                case "7":
                    $stmt->bind_result($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6]);
                    }
                    break;  
                case "8":
                    $stmt->bind_result($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6], $output[7]);
                    while ($stmt->fetch()) {
                        $results[] = array($output[0], $output[1], $output[2], $output[3], $output[4], $output[5], $output[6], $output[7]);
                    }
                    break;
                default:
                echo "HERE";
                    break;
            }
        }
    } else {
        $results = "NO RESULTS";
    }
    $stmt->fetch();
    $stmt->close();

    $this->checker = $checker;
    $this->results = $results;

    $this->result = array('num_rows' => $checker, $results);

    return $this->results;
  • 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-27T16:36:05+00:00Added an answer on May 27, 2026 at 4:36 pm

    If you are not in too deep, I highly recommend you use PDO instead of MySQLi because the MySQLi API is terrible.

    What you want is actually very difficult. Here’s a function which demonstrates the hoops you need to jump through:

    function query(MySQLi $db, $sql, array $data) {
        $stmt = $db->prepare($sql);
        if (!$stmt) return null;
        $types = str_repeat('s', count($data));
        $args = array(); // references to values in $data for call_user_func_array
        foreach ($data as $k => $v) {
            $args[$k] =& $data[$k];
        }
        array_unshift($args, $types);
        call_user_func_array(array($stmt, 'bind_param'), $args);
        $stmt->execute();
        // mysqlind driver
        if (method_exists($stmt, 'get_result')) {
            $res = $stmt->get_result();
            $rows = $res->fetch_all(MYSQLI_ASSOC);
            $res->free();
        } else { // by hand, ugh!
            $rows = array();
            $resultbinds = array(); // where results will end up
            $args = array(); // references to $resultbinds for call_user_func_array
            $meta = $stmt->result_metadata();
            while ($fieldmeta = $meta->fetch_field()) {
                $resultbinds[$fieldmeta->name] = null;
                $args[] =& $resultbinds[$fieldmeta->name];
            }
            $meta->free();
            call_user_func_array(array($stmt, 'bind_result'), $args);
            while ($stmt->fetch()) {
                $row = array();
                // copy array to dereference
                foreach ($resultbinds as $k => $v) {
                    $row[$k] = $v;
                }
                $rows[] = $row;
            }
        }
        $stmt->free_result();
        $stmt->close();
        return $rows;
    }
    

    This is how you would do the same thing in PDO:

    function query_PDO($db, $sql, $data) {
        $stmt = $db->prepare($sql);
        $stmt->execute($data);
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $stmt->closeCursor();
        return $rows;
    }
    

    Here is how to connect to MySQL using PDO:

    function connect_PDO() {
        $host = 'localhost';
        $user = 'root';
        $pass = 'root';
        $dbname = 'scratch';
        $port = 8889;
        $socket = '/Applications/MAMP/tmp/mysql/mysql.sock';
        $options = array(
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        );
        if (version_compare(PHP_VERSION, '5.3.6', '<')) {
            $options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8';
        }
        $dsn = "mysql:host={$host};port={$port};unix_socket={$socket};dbname={$dbname};charset=utf8";
        return new PDO($dsn, $user, $pass, $options);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is Lazy Loading? [Edit after reading a few answers] Why do people use
Is there a way to convert from System.Windows.Forms.HtmlElement to mshtml.IHTMLElemenet3? --edit after answer accepted
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
edit: many thanks for all the answers. Here are the results after applying the
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
EDIT After some more research I found that I cannot use a continuous form
I'm trying to immediately set a row to Edit mode after it is created.
I've got a treeview control, and have caught its after-label-edit event. I want to
I have an application that uses MSWord automation to edit some documents, after they
I've started to use XCode several months ago, after using IntelliJ for several years,

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.