Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i worked this out when going through the OReilly book, which was using the old mysql_stuff and none of the examples worked. obviously you'll need to modify it for your tables :) but it works for the tables i have. this will work for prepared statements:</p> <pre><code>&lt;?php //this file is just where my db info is, you can use the literal values require 'login.php'; $db = new mysqli($db_hostname, $db_username, $db_password, $db_database); $stmt = $db-&gt;stmt_init(); $data = array("Emily Bronte", "Wuthering Heights", "Classic Fiction", "1847", "9780553212587"); if($stmt-&gt;prepare("INSERT INTO classics(author, title, category, year, isbn) VALUES(?,?,?,?,?)")) { $stmt-&gt;bind_param('sssss', $data[0], $data[1], $data[2], $data[3], $data[4]); $stmt-&gt;execute(); $stmt-&gt;close(); } ?&gt; </code></pre> <p>this will work for queries:</p> <pre><code>&lt;?php require_once 'login.php'; $dbt = new mysqli($db_hostname, $db_username, $db_password, $db_database); if ($dbt-&gt;connect_errno) die("Unable to connect to MySQL: " . $dbt-&gt;connect_errno); $results = $dbt-&gt;query("SELECT * FROM cats"); if (!$results) die ("Database access failed: " . $db-&gt;error); $dbt-&gt;close(); echo "&lt;table&gt;&lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Family&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Age&lt;/th&gt;&lt;/tr&gt;"; for ($j = 0 ; $j &lt; $results-&gt;num_rows ; ++$j) { $row = $results-&gt;fetch_row(); echo "&lt;tr&gt;"; for ($k = 0 ; $k &lt; sizeof($row) ; ++$k) echo "&lt;td&gt;$row[$k]&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; ?&gt; </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.
 

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