本文整理汇总了PHP中DatabaseFactory::getFieldNameFromTableName方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseFactory::getFieldNameFromTableName方法的具体用法?PHP DatabaseFactory::getFieldNameFromTableName怎么用?PHP DatabaseFactory::getFieldNameFromTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseFactory
的用法示例。
在下文中一共展示了DatabaseFactory::getFieldNameFromTableName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateElementList
/**
* Updates an element list in database
* @param string $elementClass The element type to update
* @param array $updatedPropertyList An array discribing attributes to update (format is array(name => value) or array(name => array(value, operator)))
* @param string $conditions The update request conditions
* @return int The affected rows number
*/
public static function updateElementList($elementClass, $updatedPropertyList, $conditions = NULL)
{
$tableName = DatabaseFactory::getElementTableName($elementClass);
// Gets database connection instance
$databaseConnection = $elementClass::getDatabaseConnection();
// Builds request string
$request = 'UPDATE ' . $tableName . ' SET ';
foreach ($updatedPropertyList as $propertyName => &$propertyValue) {
// Don't update id
if ($propertyName == 'id') {
continue;
}
// restore $table name prefix for non ids fields
if (!StringTool::endsWith($propertyName, '_id')) {
$propertyName = DatabaseFactory::getFieldNameFromTableName($propertyName, $tableName);
}
$request .= $propertyName . ' = ' . DatabaseFactory::getFormattedPropertyValue($elementClass, $propertyName, $propertyValue) . ', ';
}
// Removes ", " at the end of the property name and value string
$request = StringTool::truncateLastChars($request, 2);
if ($conditions !== NULL) {
$request .= ' WHERE (' . $conditions . ')';
}
// Request execution on database
$affectedRowNumber = $databaseConnection->updateRequest($request);
return $affectedRowNumber;
}