![]() |
Error connecting to Database via class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Error connecting to Database via class (/showthread.php?tid=15106) Pages:
1
2
|
Error connecting to Database via class - El Forum - 01-26-2009 [eluser]macleodjb[/eluser] Hi guys, I created my own class and within the class i have some functions that query my database. I try to execute my query for the first time and i received this error. Code: A PHP Error was encountered Should i be loading my database somehow into this class? I have it loaded in the config file. Error connecting to Database via class - El Forum - 01-26-2009 [eluser]xzela[/eluser] I'm not sure what your class looks like, but you should try something like this: Code: Class Joes_class { Error connecting to Database via class - El Forum - 01-26-2009 [eluser]macleodjb[/eluser] I wish i could, now for some reason i'm getting this error message. Code: A Database Error Occurred Now i can tell you with 100% certainty that i have the correct information for my database connector. I'm starting to wanna throw out codeigniter and go to cakephp Another thing...why do i have to load my database like you suggested when it is in the autoload file under libraries? Something is definitely NOT working right. Error connecting to Database via class - El Forum - 01-26-2009 [eluser]macleodjb[/eluser] So far I've been working with codeigniter for 3 days. I've read the tutorials and the examples. Thus far, not a single thing has worked properly. For instance the .htaccess file, i copied it directly off the tutorial, doesn't work. I had to rely on this forum for someone who has a similar problem to fix it. So far i'm not seeing the benefit to using codeigniter. I've gotten one page completed since installing it and i can't continue now because i can't get to my database. It's a joke. I'm not re-inventing the wheel, i'm just trying to migrate an existing website, that was working properly. Please shed some light on me, show me how this framework helps you? Forgive my frustrations, i sincerely would like some help before i just throw this out and leave my site the way it was. Error connecting to Database via class - El Forum - 01-26-2009 [eluser]macleodjb[/eluser] ok i managed to get my database to connect. Now i have this error. Code: A PHP Error was encountered Did i forget to declare something here? Error connecting to Database via class - El Forum - 01-26-2009 [eluser]xzela[/eluser] It's possible you may have forgotten to load the class. try adding this to the function within your (register_form) controller: Code: $this->load->library('/path/to/Joes_Class'); then use this to access it: Code: $this->joes_class->hello_world(); Error connecting to Database via class - El Forum - 01-26-2009 [eluser]macleodjb[/eluser] now i get this error Code: A PHP Error was encountered This is what's inside my class Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); This is whats in my controller Code: class Register extends Controller { and this is how i am using it in my view page. Code: $industry_names = $this->joes_class->get_industry(); Error connecting to Database via class - El Forum - 01-26-2009 [eluser]xzela[/eluser] Ok, i see the issue Your class does not have a constructor Add this as your first function: Code: function Joes_class() { That should help with your class Error connecting to Database via class - El Forum - 01-26-2009 [eluser]macleodjb[/eluser] ok i did that...and got this error now. Code: A PHP Error was encountered line 7 is the line we just added to load the db Error connecting to Database via class - El Forum - 01-26-2009 [eluser]xzela[/eluser] OK, lets debug one problem at a time, to verify that your class (library) is being loaded correctly comment out this line: Code: function Joes_class() { |