![]() |
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] ok i commented it out and i get this error again. Code: A PHP Error was encountered Line 12 is my database line of my query Also returns this below the error message Fatal error: Call to a member function query() on a non-object Error connecting to Database via class - El Forum - 01-26-2009 [eluser]xzela[/eluser] aha! I think i got it, Try this: Modify your Joes_class file: Code: class Joes_class { I would highly recommend NOT using this method of getting data from a database. You've just created a model but in a difficult way. Another way to do this would be to use the Model method: Create a file in the /system/application/model directory called 'industry_model.php'; copy this code into that file Code: class Industry_model extends Model { Now in your Register controller change this line: Code: //$this->load->library('Joes_class'); And to call the get_industry() method, change this line Code: //$industry_names = $this->joes_class->get_industry(); that should do it. let me know if anything goes wrong. Error connecting to Database via class - El Forum - 01-27-2009 [eluser]macleodjb[/eluser] Thanks for taking the time to help me out so thoroughly and patiently. I did what you suggested by creating the model, and i am getting the following error. Code: Fatal error: Call to a member function result_array() on a non-object Here's my model file Code: <?php Here is my controller Code: <?php let me know if i've totally screwed this up. I'm glad to read other posts that other people are struggling just as i am. Error connecting to Database via class - El Forum - 01-27-2009 [eluser]xzela[/eluser] You almost have it! ![]() In your controller file, comment out the line to load the database class Code: function Register() Re-add it in the constructor function within your model. Your model constructor function should look something like this: Code: function Register_model(){ Now the get_industry() function will be able to access the database class. Let me now if you have any other issues. Error connecting to Database via class - El Forum - 01-27-2009 [eluser]macleodjb[/eluser] You got my hopes up. I thought i actually was getting somewhere. But no. I still get the same error. Why is it have database loaded in my autoload file, i have to also reload it in my model? Error connecting to Database via class - El Forum - 01-27-2009 [eluser]xzela[/eluser] This is so bizarre, I just copied your model and controller code verbatim and it works. That particular error message is stating that the database class is not being loaded correctly. Which is the original issue if I remember correctly. hmmm... there are a few things that can cause the database library from loading, and one of the major contributors are improper installations. What does your $config['base_url'] look like? (it's located in the /system/application/config/config.php file) what if you changed it to this: Code: $config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http"); This is a shot it the dark but it may do something... good luck! Error connecting to Database via class - El Forum - 01-27-2009 [eluser]macleodjb[/eluser] wow, there sure don't outline this in the user docs. my config file shows this Code: $config['base_url'] = "http://www.example.com/"; I really appreciate you taking the time to troubleshoot for me. This is frustrating me beyond belief. edit:your patch didn't affect my problem. Do you think this is a config problem or perhaps a server problem? Error connecting to Database via class - El Forum - 01-27-2009 [eluser]xzela[/eluser] hmmm... good question, do you have a local copy on your workstation or is it only up on your server? I would guess it is a configuration problem, because as long as you're using apache1.5/2 and php5 you should be good to go. By the way are you using MySQL or something else? Error connecting to Database via class - El Forum - 01-27-2009 [eluser]macleodjb[/eluser] I've got it working now. I deleted all files and unpacked it again. Redid my one model and it works fine now. Jesus this was exhausting. I write the pages locally and then upload to my server. I've got it now, but thank you very very much for having the patience to sit through my frustrations. thanks again. Error connecting to Database via class - El Forum - 01-27-2009 [eluser]xzela[/eluser] good to hear it's working now. That's a relief. no problem for the help, that's what these forums are for. ![]() good luck on your site. |