Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Answer from Emmanuel works fine, if only one row is selected! If the query select multiple rows, the $results-Array holds for every row a result, but the result is always filled with the last entry. With a little change in the fetch()-while it work well.</p> <p>$sqlStmt is an string, filled with the mysql-query</p> <p>$params is an array, filled with the variables that should passed</p> <p>$results is an empty array, that holds the result</p> <pre><code> if (!is_string($sqlStmt) || empty($sqlStmt)) { return false; } // initialise some empty arrays $fields = array(); $results = array(); if ($stmt = $this-&gt;prepare($sqlStmt)) { // bind params if they are set if (!empty($params)) { $types = ''; foreach($params as $param) { // set param type if (is_string($param)) { $types .= 's'; // strings } else if (is_int($param)) { $types .= 'i'; // integer } else if (is_float($param)) { $types .= 'd'; // double } else { $types .= 'b'; // default: blob and unknown types } } $bind_names[] = $types; for ($i=0; $i&lt;count($params);$i++) { $bind_name = 'bind' . $i; $$bind_name = $params[$i]; $bind_names[] = &amp;$$bind_name; } call_user_func_array(array($stmt,'bind_param'),$bind_names); } // execute query $stmt-&gt;execute(); // Get metadata for field names $meta = $stmt-&gt;result_metadata(); // This is the tricky bit dynamically creating an array of variables to use // to bind the results while ($field = $meta-&gt;fetch_field()) { $var = $field-&gt;name; $$var = null; $fields[$var] = &amp;$$var; } // Bind Results call_user_func_array(array($stmt,'bind_result'),$fields); // Fetch Results $i = 0; while ($stmt-&gt;fetch()) { $results[$i] = array(); foreach($fields as $k =&gt; $v) $results[$i][$k] = $v; $i++; } // close statement $stmt-&gt;close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload