Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.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 “法尔孔杀手回来了”;0“;用于创建/保存后的模型id_Php_Database_Phalcon - Fatal编程技术网

Php “法尔孔杀手回来了”;0“;用于创建/保存后的模型id

Php “法尔孔杀手回来了”;0“;用于创建/保存后的模型id,php,database,phalcon,Php,Database,Phalcon,我正在为我的项目使用,但是当我尝试创建/保存模型实例到数据库时,我遇到了一个问题,即id字段在我的模型中总是返回“0” $customer = new Customer(); $customer->name = "John"; $customer->age = 18; $customer->create(); dd($customer->id); // return "0" 数据成功保存在数据库中,id字段具有正确的(自动增量)数

我正在为我的项目使用,但是当我尝试创建/保存模型实例到数据库时,我遇到了一个问题,即id字段在我的模型中总是返回“0”

$customer = new Customer();
$customer->name = "John";
$customer->age = 18;
$customer->create();
dd($customer->id); // return "0"
数据成功保存在数据库中,id字段具有正确的(自动增量)数据

如果我尝试使用原始Phalcon,它会正常工作(返回正确的id)

我找到了一些在数据库配置中设置
'persistent'=>true的解决方案。并且它正确地返回id

'mysql' => [
    'host'     => env('DB_HOST', 'localhost'),
    'port'     => env('DB_PORT', 3306),
    'username' => env('DB_USERNAME'),
    'password' => env('DB_PASSWORD'),
    'dbname'   => env('DB_DATABASE', 'slayer'),
    'persistent' => true,
    'charset'  => env('DB_CHARSET', 'utf8'),
    'class'    => Phalcon\Db\Adapter\Pdo\Mysql::class,
],
但我不确定这个解决方案是否正确。谁能帮我看看这里出了什么问题,我该怎么办

供参考:

  • PHP7.2(我也尝试使用7.0和5.6)
  • 法尔康3.4
  • MySQL 8.0(我也尝试使用5.4)