class SQLFIReader in Feed Import 8
SQL Reader class, used te read data with SQL queries.
Hierarchy
- class \Drupal\feed_import_base\FeedImportConfigurable
- class \Drupal\feed_import_base\FeedImportReader
- class \Drupal\feed_import_base\FeedImportUniVectorReader
- class \Drupal\feed_import_base\SQLFIReader
- class \Drupal\feed_import_base\FeedImportUniVectorReader
- class \Drupal\feed_import_base\FeedImportReader
Expanded class hierarchy of SQLFIReader
File
- feed_import_base/
src/ SQLFIReader.php, line 7
Namespace
Drupal\feed_import_baseView source
class SQLFIReader extends FeedImportUniVectorReader {
/**
* {@inheritdoc}
*/
public function init() {
// Require dsn and query.
if (empty($this->options['dsn']) || empty($this->options['query'])) {
return FALSE;
}
// Set default options.
$this->options += array(
'user' => 'root',
'pass' => NULL,
'params' => array(),
);
// Parse params if needed.
if (!is_array($this->options['params'])) {
$params = static::cleanLines($this->options['params']);
$this->options['params'] = array();
foreach ($params as &$param) {
$param = explode('=', $param, 2);
if (count($param) == 2) {
$this->options['params'][$param[0]] = $param[1];
}
else {
$this->options['params'][] = $param[0];
}
}
unset($param, $params);
}
// Connect to db.
$db = new PDO($this->options['dsn'], $this->options['user'], $this->options['pass']);
if (!$db) {
return FALSE;
}
// Prepare query.
$this->items = $db
->prepare($this->options['query'], array(
PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY,
));
// Execute query
if (!$this->items
->execute($this->options['params'])) {
return FALSE;
}
return TRUE;
}
/**
* {@inheritdoc}
*/
public function get() {
return $this->items
->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedImportConfigurable:: |
protected | property | ||
FeedImportConfigurable:: |
public static | function | Helper function to get lines of a string | |
FeedImportConfigurable:: |
public | function | Sets options for this instance | 4 |
FeedImportReader:: |
protected | property | ||
FeedImportReader:: |
public | function | Returns a stream context | |
FeedImportReader:: |
final public | function | Constructor of reader. Constructor is final but you'll have to implement init() to init your reader. | |
FeedImportReader:: |
public | function | Destructor. | 2 |
FeedImportUniVectorReader:: |
public | function |
Override this to preprocess your paths before they are used in map(). Overrides FeedImportReader:: |
1 |
FeedImportUniVectorReader:: |
public | function |
Returns a value mapped from obj by path. Overrides FeedImportReader:: |
|
SQLFIReader:: |
public | function |
This method returns the next available item or NULL if there are no items
left. Overrides FeedImportReader:: |
|
SQLFIReader:: |
public | function |
Here you'll init your reader. Overrides FeedImportReader:: |