本文整理汇总了PHP中ADORecordSet::GetAssoc方法的典型用法代码示例。如果您正苦于以下问题:PHP ADORecordSet::GetAssoc方法的具体用法?PHP ADORecordSet::GetAssoc怎么用?PHP ADORecordSet::GetAssoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ADORecordSet
的用法示例。
在下文中一共展示了ADORecordSet::GetAssoc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recordset_to_assoc
/**
* Utility function to turn a result set into an associative array of records
* This method turns a result set into a hash of records (keyed by the first
* field in the result set)
*
* @param ADORecordSet $rs An ADODB RecordSet object.
* @return mixed An array of objects, or false if the RecordSet was empty.
* @throws SQLException
* @access private
*/
function recordset_to_assoc(ADORecordSet $rs)
{
if ($rs && $rs->RecordCount() > 0) {
// First of all, we are going to get the name of the first column
// to introduce it back after transforming the recordset to assoc array
// See http://docs.moodle.org/en/XMLDB_Problems, fetch mode problem.
$firstcolumn = $rs->FetchField(0);
// Get the whole associative array
if ($records = $rs->GetAssoc(true)) {
foreach ($records as $key => $record) {
$record[$firstcolumn->name] = $key;
$objects[$key] = (object) $record;
}
return $objects;
} else {
return false;
}
} else {
return false;
}
}