Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 最后一个标识符问题_Php_Doctrine - Fatal编程技术网

Php 最后一个标识符问题

Php 最后一个标识符问题,php,doctrine,Php,Doctrine,在尝试运行以下程序时,我遇到了以下问题: $store = new Store(); $store->url =$this->form_validation->set_value('website'); $store->save(); $store_id = $store->identifier(); Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'Cou

在尝试运行以下程序时,我遇到了以下问题:

$store = new Store();
$store->url =$this->form_validation->set_value('website');
$store->save();
$store_id = $store->identifier();


Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'Couldn't get last insert identifier.' in /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php:932 Stack trace: #0 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php(632): Doctrine_Connection_UnitOfWork->_assignIdentifier(Object(Category_store_assn)) #1 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php(562): Doctrine_Connection_UnitOfWork->processSingleInsert(Object(Category_store_assn)) #2 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php(81): Doctrine_Connection_UnitOfWork->insert(Object(Category_store_assn)) #3 /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Record.php(1691): Doctrine_Connection_UnitOfWork->saveGraph(Object(Category_store_assn)) #4 /home/yummm/public_html/system/application/controllers/auth.php(375): Doctrine_Reco in /home/yummm/public_html/system/application/plugins/doctrine/lib/Doctrine/Connection/UnitOfWork.php on line 932

当我回显$store_id时,它似乎在毫无问题地获取最后一个id。知道为什么即使ID正确传递,仍然会出现此错误吗?

可能是您重写了
setTableDefinition()
方法,现在没有
hasColum()
调用您的
ID
属性。

我发现hasColum()中主键字段的“自动增量”=>true存在问题。 如果我将“autoincrement”=>设置为false,那么问题就消失了


但该表的主键字段是一个自动递增字段。奇怪的是,其他计算机上没有任何错误。所有计算机上的应用程序和数据库都是相同的。

现在我发现这是因为PDO对象的lastInsertId()方法返回0。 因此,假设问题出在PDO驱动程序中,而不是条令错误。 需要重新安装PHP或PDO扩展。
另外,请参见。

列定义本身可能未设置为自动增量。使用以下命令检查表定义:(假设为MySQL)


并确保您的ID字段标记为自动增量。如果不是,则Dority将尝试获取表的最后一个标识符,但将失败,因为只有auto_increment columns响应MySQL的last_INSERT_ID()函数。

存储表中的ID可能未设置为autoincrement。在这种情况下,您必须通过hasColumn函数中使用的混合选项参数将其“告知”到doctrine记录模型:

$this->hasColumn('id', 'integer', 11, array(
    'primary' => true,
    'autoincrement' => false) 
    );

或者根据需要设置ID自动增量。

我的情况是PDO驱动程序错误

对于我来说,第1.2条也是同样的问题。这个没用:

    $this->hasColumn('id', 'int', null, array(
    'primary'       => true,
    'autoincrement' => true
));
这一次:

    $this->hasColumn('id', 'integer', 4, array(
      'type' => 'integer',
      'length' => 4,
      'unsigned' => true,
      'primary' => true,
      'autoincrement' => true,
));

不知道为什么会有差异,但希望能有所帮助。

此错误报告已关闭五年。PDO驱动程序应该正常工作。
    $this->hasColumn('id', 'integer', 4, array(
      'type' => 'integer',
      'length' => 4,
      'unsigned' => true,
      'primary' => true,
      'autoincrement' => true,
));