Son PHP / MySQL içinde satır oluşturulan Accessing

4 Cevap php

Nasıl sadece PHP / MySQL ile DB sokulduktan satır erişmek için?

I var:

    $sql = 'INSERT INTO `jos_db`.`jos_sections` (`id`,  `name`) VALUES (NULL, \'foo\')';
    mysql_query($sql, $dbi);

    bar();

Nasıl I) (bar yeni satır girebilirim?

4 Cevap

Eğer 'id' sütunu bir otomatik artım ise, kullanabilirsiniz mysql_insert_id:

Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.


The example given in the manual looks like this :

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());

Sen son öğe mysql_insert_id ile eklenen alabilirsiniz ()

http://us.php.net/manual/en/function.mysql-insert-id.php

Veritabanına eklenen son satırı seçmek için mysql_insert_id () işlevini kullanın.

SELECT rows from table where id = last_inserted_id

PHP fonksiyonunu kullanarak mysql_insert_id() Eğer eklenen son satırın id dönecektir.