mitsos Posted November 11, 2014 Report Posted November 11, 2014 I can't get a select statement to fire up. Admitedly PHP isn't my strong suit, but I've tried everything I can think of. This function is supposed to return results for creating a new package. Here are the related functions: private function DBConnection ($host_name, $data_base, $user_name, $pass_word) { $db = new PDO ("mysql:host=$host_name;dbname=$data_base", "$user_name", "$pass_word"); } private function getPackages($module_row) { if (!isset($this->DataStructure)) Loader::loadHelpers($this, array("DataStructure")); if (!isset($this->ArrayHelper)) $this->ArrayHelper = $this->DataStructure->create("Array"); try { $db = $this->DBConnection($module_row->meta->host_name, $module_row->meta->data_base, $module_row->meta->user_name, $module_row->meta->pass_word); $stmt = $db->query("SELECT * FROM Packages"); $packages = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { } return $packages; } Turning on MariaDB's general query log shows the connection going through, but the query isn't executed. Please feel free to throw rotten tomatoes if you see a stupid mistake somewhere. Quote
Tyson Posted November 11, 2014 Report Posted November 11, 2014 Curious why you are trying to call PDO directly? If you're working from Blesta, you can use the Record component for queries. mitsos, Michael and ModulesBakery 3 Quote
mitsos Posted November 11, 2014 Author Report Posted November 11, 2014 See? I knew I was doing it wrong. Thanks for pointing me in the right direction Quote
Tyson Posted November 12, 2014 Report Posted November 12, 2014 You're welcome. And I wouldn't necessarily say it's wrong, but there is an alternative, easier, way to query the database from Blesta. Quote
mitsos Posted November 12, 2014 Author Report Posted November 12, 2014 I still can't get it to fire up the query. A few more details: The code snippet is from a module I'm developing for a custom control panel at the-place-that-puts-food-on-the-table. The code is supposed to connect to a remote (keyword, NOT the blesta DB) database (which it does correctly) and execute a select query on the *remote* database (which doesn't work). The query is supposed to return packages for the package creation page, using the remote database for their names/specs. I'm basically stuck on this step and don't know how to fix it. Any help is much appreciated. Quote
mitsos Posted November 12, 2014 Author Report Posted November 12, 2014 FINALLY! private function getPackages($module_row) { try { $db = $this->DBConnection($module_row->meta->host_name, $module_row->meta->data_base, $module_row->meta->user_name, $module_row->meta->pass_word); $query = $this->DBQuery($db); } catch (PDOException $e) { } Quote
mitsos Posted November 13, 2014 Author Report Posted November 13, 2014 Yeap, it was a combination of head scratching and cursing that got it working :-) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.