[[dbconnect]] [[dbaccess]]
<?php $host = 'IPAddress'; $username = 'username'; $password = 'password'; $dbname = 'dbname'; $port = 3306; $charset = 'utf-8'; $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset"; $xpdo = new xPDO($dsn, $username, $password); echo $o = ($xpdo->connect()) ? 'Connected </br>' : 'Not Connected';
$results = $xpdo->getCollection('LogData',array('callid' => 7382054)); $output = ''; if ($results) { foreach($results as $result) { $fields = $result->toArray(); $output .= $modx->getChunk('ShowData', $fields); } } else { return 'No items found.'; } return $output;
<p>Call Id: [[+callid]]<br /> Dialled Number: [[+diallednumber]]<br /> Call Date: [[+calldate]] </p>
[[$SearchFrom]]
[[dbconnect]] [[!dbformtest]] <form method="post" action="[[~[[*id]]]]"> <input type="text" name='search' id='search' value="[[+search]]" /> <input type='submit' name='submit' id='submit' value='submit'/> </form>
<?php if (isset($_POST['search'])) { /* if (!$xpdo->addPackage('nhs','/home/sites/paradoxal.co.uk/public_html/nhs/core/components/nhs/model/','')) { print 'There was a problem adding your package.'; }; */ echo "Search is set"; $search = $_POST['search']; print_r ($search); } else { return 'Search is not set'; }
This question has been answered by jgulledge19. See the first response.
if (!isset($modx->myDB)) { // load your DB stuff: // could put in external file... $modx->myDB = new xPDO($dsn, $username, $password); } // then you can use it: if (!$modx->myDB->addPackage('nhs','/home/sites/paradoxal.co.uk/public_html/nhs/core/components/nhs/model/','')) { print 'There was a problem adding your package.'; };
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /home/sites/paradoxal.co.uk/public_html/nhs/core/xpdo/xpdo.class.php on line 1359
if (!isset($modx->myDB)) { $host = 'IPAdress'; $username = 'Username'; $password = 'Password'; $dbname = 'dbname'; $port = 3306; $charset = 'utf-8'; $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset"; $modx->myDB = new xPDO($dsn, $username, $password); echo $o = ($xpdo->connect()) ? 'Connected </br>' : 'Not Connected'; } if (isset($_POST['search'])) { $path = MODX_CORE_PATH . 'components/nhs/'; if (!$modx->myDB->addPackage('nhs', $path . 'model/','')) { print 'There was a problem adding your package.'; }; $search = $_POST['search']; $results = $modx->myDB->getCollection('LogData',array('diallednumber' => $search)); $output = ''; if ($results) { foreach($results as $result) { $fields = $result->toArray(); $output .= $modx->getChunk('ShowData', $fields); } } else { return 'No items found.'; } } else { $output = $modx->getChunk('SearchFrom'); } return $output;
else { $output = $modx->getChunk('SearchFrom'); }