Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you're doing here is unnecessary thanks to <a href="http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html" rel="nofollow"><code>AUTO_INCREMENT</code></a> in mysql. Run this command from PhpMyAdmin (or another DB management system):</p> <pre><code>ALTER TABLE db MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT; </code></pre> <p>Now when insert a row into <code>db</code> mysql will assign the ID for you:</p> <pre><code>INSERT INTO db (id, column1, column2) VALUES(NULL, 'abc', 'def'); </code></pre> <p><code>SELECT * FROM db;</code>:</p> <pre><code>+--+-------+-------+ |id|column1|column2| +--+-------+-------+ |1 |old |oldrow | +--+-------+-------+ |2 |abc |def | &lt;--- Your newly inserted row, with unique ID +--+-------+-------+ </code></pre> <p>If you delete a row, it is true that there will be an inconsistency in the order of the ID's, but this is ok. IDs are not intended to denote the numeric position of a row in a table. They are intended to uniquely identify each row so that you can perform actions on it and reference it from other tables with foreign keys.</p> <hr> <p>Also if you need to grab a group of ID's (stored in an array, for example), it is much more efficient to perform one query with an <code>IN</code> statement.</p> <pre><code>$ids = array(1,2,3,4,5,6); $in = implode(',', $ids); mysql_query('SELECT * FROM db WHERE id IN ('.$in.')'); </code></pre> <p>However, if you want all rows just use:</p> <pre><code>SELECT * FROM dbs; </code></pre> <p>But be weary of <a href="http://bobby-tables.com/" rel="nofollow">bobby tables</a>. </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.
    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.
    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