From: Steve Sutton Date: Thu, 9 Jul 2015 20:53:38 +0000 (-0400) Subject: More minor updates on the plugin. X-Git-Tag: v0.0.2^2~49 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=4bf366b02e3b228f538b52df8c802ace94ff54f1;p=WP-Plugins%2Fglm-wp-importer.git More minor updates on the plugin. Create new function for the database connection and move that logic into the function. --- diff --git a/controllers/Import.php b/controllers/Import.php index d740719..1cf404e 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -43,7 +43,27 @@ class Toolbox_Import extends WP_Importer { private $_dbh; - function __construct(){} + function __construct() + { + } + + function connect() + { + // read optios for the import and if they aren't set then give a warning. + $options = get_option(GLM_WP_IMPORT_SETTINGS); + // try making a postgres connection to the database + $connString = 'dbname=' . $options['db_name']; + $connString .= ' host=' . $options['db_host']; + $connString .= ' user=' . $options['db_user']; + $driverOptions = array( + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC + ); + $this->_dbh = new PDO('pgsql:'.$connString, null, null, $driverOptions); + $this->_dbh->setAttribute( + PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION + ); + } function header() { @@ -59,25 +79,10 @@ function greet() { echo '

Hello there person!

'; - // read optios for the import and if they aren't set then give a warning. - $options = get_option(GLM_WP_IMPORT_SETTINGS); - echo '
'.print_r($options, true).'
'; - // try making a postgres connection to the database - $connectionString = 'dbname=' . $options['db_name']; - $connectionString .= ' host=' . $options['db_host']; - $connectionString .= ' user=' . $options['db_user']; - $driverOptions = array( - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC - ); - $this->_dbh = new PDO('pgsql:'.$connectionString, null, null, $driverOptions); - $this->_dbh->setAttribute( - PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION - ); - echo '
'.print_r($this->_dbh, true).'
'; + $this->connect(); $sql = "SELECT * FROM toolbox.pages"; $data = $this->_dbh->query($sql)->fetchAll(); - echo '
'.print_r($data, true).'
'; + printf('

Found %d Pages

', count($data)); } function dispatch()