+ Add getColumns function for dao.

This commit is contained in:
zhujinyong
2022-11-09 15:44:49 +08:00
parent 4d8529153f
commit b4d4e33e23
+30
View File
@@ -700,6 +700,36 @@ class baseDAO
}
}
/**
* 返回SQL结果的所有字段信息。
* Return the fields meta of PDOStatement.
*
* @param string|PDOStatement $stmt
* @access public
* @return array
*/
public function getColumns($stmt)
{
/* 如果是SQL查询语句,先执行查询获得 PDO stmt. */
/* If it is SQL string, query to get PDO stmt. */
if(is_string($stmt)) $stmt = $this->query($stmt);
$fields = array();
try
{
for($columnIndex = 0; $columnIndex < $stmt->columnCount(); $columnIndex++)
{
$fields[] = $stmt->getColumnMeta($columnIndex);
}
return $fields;
}
catch (PDOException $e)
{
$this->sqlError($e);
}
}
/**
* 将记录进行分页,自动设置limit语句。
* Page the records, set the limit part auto.