本文整理汇总了PHP中moodle_database::insert_records方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_database::insert_records方法的具体用法?PHP moodle_database::insert_records怎么用?PHP moodle_database::insert_records使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodle_database
的用法示例。
在下文中一共展示了moodle_database::insert_records方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: commit
/**
* Commit new records.
*
* @return void
*/
public function commit()
{
$request = (object) array('pid' => getmypid(), 'threadid' => ZEND_THREAD_SAFE ? zend_thread_id() : null, 'uid' => getmyuid(), 'url' => $this->url->out_as_local_url(false), 'hostname' => gethostname(), 'memory' => memory_get_usage(), 'peakmemory' => memory_get_peak_usage());
// Not supported on Windows until PHP 7
if (function_exists('getrusage')) {
$resourceusage = getrusage();
$request->numswaps = $resourceusage['ru_nswap'];
$request->numpagefaults = $resourceusage['ru_majflt'];
$request->usertime = $resourceusage['ru_utime.tv_usec'];
}
$request->id = $this->db->insert_record('telemetry_request', $request);
foreach ($this->additionalstate as $collector) {
$table = $collector->get_table();
$records = $collector->get_records();
foreach ($records as $record) {
$record->requestid = $request->id;
}
$this->db->insert_records($table, $records);
}
}
示例2: insert_event_entries
/**
* Insert events in bulk to the database.
*
* @param array $evententries raw event data
*/
protected function insert_event_entries($evententries)
{
if (!$this->init()) {
return;
}
if (!($dbtable = $this->get_config('dbtable'))) {
return;
}
try {
$this->extdb->insert_records($dbtable, $evententries);
} catch (\moodle_exception $e) {
debugging('Cannot write to external database: ' . $e->getMessage(), DEBUG_DEVELOPER);
}
}
示例3: insert_records
/**
* Insert multiple records into database as fast as possible.
*
* Order of inserts is maintained, but the operation is not atomic,
* use transactions if necessary.
*
* This method is intended for inserting of large number of small objects,
* do not use for huge objects with text or binary fields.
*
* @since Moodle 2.7
*
* @param string $table The database table to be inserted into
* @param array|Traversable $dataobjects list of objects to be inserted, must be compatible with foreach
* @return void does not return new record ids
*
* @throws coding_exception if data objects have different structure
* @throws dml_exception A DML specific exception is thrown for any errors.
*/
public function insert_records($table, $dataobjects)
{
if (!is_array($dataobjects) and !$dataobjects instanceof Traversable) {
throw new coding_exception('insert_records() passed non-traversable object');
}
// PostgreSQL does not seem to have problems with huge queries.
$chunksize = 500;
if (!empty($this->dboptions['bulkinsertsize'])) {
$chunksize = (int) $this->dboptions['bulkinsertsize'];
}
$columns = $this->get_columns($table, true);
// Make sure there are no nasty blobs!
foreach ($columns as $column) {
if ($column->binary) {
parent::insert_records($table, $dataobjects);
return;
}
}
$fields = null;
$count = 0;
$chunk = array();
foreach ($dataobjects as $dataobject) {
if (!is_array($dataobject) and !is_object($dataobject)) {
throw new coding_exception('insert_records() passed invalid record object');
}
$dataobject = (array) $dataobject;
if ($fields === null) {
$fields = array_keys($dataobject);
$columns = array_intersect_key($columns, $dataobject);
unset($columns['id']);
} else {
if ($fields !== array_keys($dataobject)) {
throw new coding_exception('All dataobjects in insert_records() must have the same structure!');
}
}
$count++;
$chunk[] = $dataobject;
if ($count === $chunksize) {
$this->insert_chunk($table, $chunk, $columns);
$chunk = array();
$count = 0;
}
}
if ($count) {
$this->insert_chunk($table, $chunk, $columns);
}
}