php - Kohana3框架中表的列名作为变量

标签 php mysql insert kohana

我在 Kohana3 框架中有这样一个代码,它在 Days 表中保存值。

$column_names=array('morning','day','evening','night');
$values=array('abc','xyz','eeeee','ooooo');

$result=ORM::factory('Day');
$result->morning=$values[0];
$result->day=$values[1];
$result->evening=$values[2];
$result->night=$values[3];
$result->save();

如何使用 $column_names 编写类似的内容,即使用变量作为列名:

$result->$column_names[3]=$values[3];

最佳答案

您可以使用括号将数组括起来。

$result->{$column_names[3]} = $values[3];

关于php - Kohana3框架中表的列名作为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13896607/

相关文章:

php - MySQL 看起来不错,但 Laravel 不喜欢它

php - 正则表达式(php 中的 preg_match): last groups in the output array don't work correctly

java - 当使用系统属性定义资源时,获取 SQLException : Driver:org. hsqldb.jdbcDriver 在 tomee 中为 URL 返回 null

php - 未定义索引 - 创建文章

MYSQL插入concat结果

php - Laravel 4 中具有特定角色的用户的额外字段

php - 如何使用 codeigniter 使用多个或单个 id 在单个查询中更新多行或单行?

java - 使用 Quarkus Reactive MySQL Clients/io.vertx.mysqlclient 进行服务器故障转移

php - 这个 MySQL 准备好的语句有什么问题? "unkown column in where clause"

mysql - 如何使用自动递增的列(字段)将数据插入 MySQL?