Note that there are some explanatory texts on larger screens.

plurals
  1. POSafe way to fetch data with mysql/php
    primarykey
    data
    text
    <p>i wrote this code before i was aware of the use of prepared statements and what it does to SQL injections. Now i'm also aware of how messy it is to fetch arrays with prepared statements. So i was wondering if this piece of code is safe to use since it doesn't use any user submitted information to fetch the rows. </p> <p>What it does is to identify the row in the db table by using a session id, session is ensured by a login_check function etc..: </p> <pre><code>$username = $_SESSION['username']; $select = mysqli_query($link, " SELECT product_id, product_title, product_value FROM product WHERE user_id='$username'"); while ($row = mysqli_fetch_assoc($select)) { $product[] = array( 'product_id' =&gt; $row['product_id'], 'product_title' =&gt; $row['product_title'], 'product_value' =&gt; $row['product_value']); } </code></pre> <p>Some information regarding this issue would really be appreciated since things were going so well until i got to know of the prepared statements..</p> <p><strong>Edit</strong><br /> So, i kinda went in another direction and skipped the array part completely for this query. Instead i went with the prepared statement and did something like this..:</p> <p><code>$select_stmt = $db-&gt;prepare("SELECT etc...)</code><br /> <code>$select_stmt-&gt;bind_param("CODE")</code><br /> <code>$select_stmt-&gt;execute();</code><br /> And so on..</p> <p>But the thing is that my bind_result got pretty big (?) with 14 variables. Perhaps this is a stupid question but will that slow down my site compared to the old way with using a single array (if 14 even is considered "big")? This is a common query that hopefully many users will use simultaniously and often. Prepared statements are new for me so..</p> <p>Thanks sofar for the help people. </p>
    singulars
    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.
 

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