更新数据库 CakePHP 中的单个记录
Update a single record in database CakePHP
我正在尝试使用函数“updateAll”更新数据库的单个记录,并按单个“id”进行过滤。
$this->Factura->updateAll(
array(
'Factura.I_COBRADO' => $factura['Factura']['I_TOTAL'],
'Factura.L_COBRADA' => 1,
'Factura.FH_COBRO' => date('Y-m-d H:i:s'),
'Factura.S_FORMAPAGO' => 'tarjeta',
'Factura.FK_FORMAPAGOCOBRO' => 41
),
array(
'Factura.PK_FACTURA' => $factura['Factura']['PK_FACTURA'])
)
但是我得到这个错误:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '15:10:55, Factura
.S_FORMAPAGO
= tarjeta, Factura
.FK_FORMAPAGOCOBRO
= 41 ' at line 1
SQL Query: UPDATE itramit_daily_desarrollo
.facturas
AS Factura
LEFT JOIN itramit_daily_desarrollo
.expedientes
AS Expediente
ON (Factura
.FK_EXPEDIENTE
= Expediente
.PK_EXPEDIENTE
) LEFT JOIN itramit_daily_desarrollo
.expedientes
AS ExpedienteFactura
ON (Factura
.FK_EXPEDIENTE
= ExpedienteFactura
.PK_EXPEDIENTE
) LEFT JOIN itramit_daily_desarrollo
.municipios
AS Municipio
ON (Factura
.FK_MUNICIPIO
= Municipio
.PK_MUNICIPIO
) LEFT JOIN itramit_daily_desarrollo
.valoraciones
AS Valoracione
ON (Factura
.FK_VALORACION
= Valoracione
.PK_VALORACION
) LEFT JOIN itramit_daily_desarrollo
.liquidaciones
AS Liquidacione
ON (Factura
.FK_LIQUIDACION
= Liquidacione
.PK_LIQUIDACION
) LEFT JOIN itramit_daily_desarrollo
.formaspagoscobros
AS Formaspagoscobro
ON (Factura
.FK_FORMAPAGOCOBRO
= Formaspagoscobro
.PK_FORMAPAGOCOBRO
) SET Factura
.I_COBRADO
= 165.00, Factura
.L_COBRADA
= 1, Factura
.FH_COBRO
= 2021-08-16 15:10:55, Factura
.S_FORMAPAGO
= tarjeta, Factura
.FK_FORMAPAGOCOBRO
= 41 WHERE Factura
.PK_FACTURA
= 166569
运行 您通过 MySQL Workbench 查询,我看到了
Factura.FH_COBRO = 2021-08-16 15:10:55
是语法错误的原因。看起来 CakePHP 没有在数据值周围添加引号。
尝试:
'Factura.FH_COBRO' => "'" + date('Y-m-d H:i:s') + "'",
'Factura.S_FORMAPAGO' => "'tarjeta'",
我正在尝试使用函数“updateAll”更新数据库的单个记录,并按单个“id”进行过滤。
$this->Factura->updateAll(
array(
'Factura.I_COBRADO' => $factura['Factura']['I_TOTAL'],
'Factura.L_COBRADA' => 1,
'Factura.FH_COBRO' => date('Y-m-d H:i:s'),
'Factura.S_FORMAPAGO' => 'tarjeta',
'Factura.FK_FORMAPAGOCOBRO' => 41
),
array(
'Factura.PK_FACTURA' => $factura['Factura']['PK_FACTURA'])
)
但是我得到这个错误:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '15:10:55,
Factura
.S_FORMAPAGO
= tarjeta,Factura
.FK_FORMAPAGOCOBRO
= 41 ' at line 1
SQL Query: UPDATE
itramit_daily_desarrollo
.facturas
ASFactura
LEFT JOINitramit_daily_desarrollo
.expedientes
ASExpediente
ON (Factura
.FK_EXPEDIENTE
=Expediente
.PK_EXPEDIENTE
) LEFT JOINitramit_daily_desarrollo
.expedientes
ASExpedienteFactura
ON (Factura
.FK_EXPEDIENTE
=ExpedienteFactura
.PK_EXPEDIENTE
) LEFT JOINitramit_daily_desarrollo
.municipios
ASMunicipio
ON (Factura
.FK_MUNICIPIO
=Municipio
.PK_MUNICIPIO
) LEFT JOINitramit_daily_desarrollo
.valoraciones
ASValoracione
ON (Factura
.FK_VALORACION
=Valoracione
.PK_VALORACION
) LEFT JOINitramit_daily_desarrollo
.liquidaciones
ASLiquidacione
ON (Factura
.FK_LIQUIDACION
=Liquidacione
.PK_LIQUIDACION
) LEFT JOINitramit_daily_desarrollo
.formaspagoscobros
ASFormaspagoscobro
ON (Factura
.FK_FORMAPAGOCOBRO
=Formaspagoscobro
.PK_FORMAPAGOCOBRO
) SETFactura
.I_COBRADO
= 165.00,Factura
.L_COBRADA
= 1,Factura
.FH_COBRO
= 2021-08-16 15:10:55,Factura
.S_FORMAPAGO
= tarjeta,Factura
.FK_FORMAPAGOCOBRO
= 41 WHEREFactura
.PK_FACTURA
= 166569
运行 您通过 MySQL Workbench 查询,我看到了
Factura.FH_COBRO = 2021-08-16 15:10:55
是语法错误的原因。看起来 CakePHP 没有在数据值周围添加引号。
尝试:
'Factura.FH_COBRO' => "'" + date('Y-m-d H:i:s') + "'",
'Factura.S_FORMAPAGO' => "'tarjeta'",