English 中文(简体)
Doctrine2:发现表上的最后识别资料?
原标题:Doctrine2: discover last ID of the table?

我写了一个问询,我不得不在一张带有理论的表格中发现最后插入项目的识别。

我不得不:

$this->getDoctrine()->getConnection()->prepare("SELECT MAX(id) FROM Commit");
问题回答

When you flush, Doctrine will assign the entity id to your entity. Let say your entity is:

class MyEntity {
  protectd $id;

  public function getId() {
     return $this->id;
  }

  public function setId($id) {
     $this->id = $id;
  }
}

当你做实体管理:面粉,最后插入 d 将被分配到补贴财产。 然后,你只花了两美元,然后用上了上门。

正如Cerad所言,你真的要找回自己的实体,做另一个问询。 相反,你可以让实体经理(最新)知道自己的身份。 例如。

$myEntity = new EntitiesMyEntity();
$myEntity->setProperty($someValue);

// Save my entity ($em = EntityManager)
$em->persist($myEntity);

// Flush my entity manager
try {
   $em->flush();
} catch (Exception $e)
{
}

// Refresh my entity (populate the identifier)
$em->refresh($myEntity);

// Tada
echo $myEntity->getId();

理论没有这样做的任何方法,只有最近才投入使用,只有插入的使用者才能使用。 但是,如果你不想质疑这一表格,因为它是一片大事,或者是因为其他东西,你可以再做一表来储存这种id,并更新一点,即某些用户每增加一个新内容。 如果你不想这样做,那么你就必须这样做。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签