Connecting to a database |
[eluser]grejsimojs[/eluser]
Hey peeps, I'd like to connect my form to my database. I've been looking through the user guide and it has gotten me a little confused, yet I think I understand it better now than before. As I understand, I have to connect to the database using a model? What should I really have in the model? Where should this be written? In the model, in my controller or in database.php? Code: $this->load->database(''); Thank you!
[eluser]InsiteFX[/eluser]
If you are using the database all the time you can autoload it in ./application/config/autoload.php as a library. Otherwise load it in your constructor.
[eluser]grejsimojs[/eluser]
Alright, I do not use it all the time. Loading it in the constructor would be great, but how exactly do I do that? Is my constructor in the model?
[eluser]Adam Liszkai[/eluser]
Hi! You must set the database settings in your /application/config/database.php And then load in your class or modell constuct: Code: function __constuct() Or load somwhere (before you use database) in your php code: Code: $this->load->database(); And do not try load in view or template files ![]() And then read the documentation for more: http://ellislab.com/codeigniter/user-gui...index.html Cheers!
[eluser]grejsimojs[/eluser]
Hey Adam! Thanks for the help, very appreciated! This is what my model looks like right now: Code: <? How do I put the Model into work?
[eluser]Adam Liszkai[/eluser]
If you have multiple databases then you must fill out the /application/config/database.php Code: $config['hostname'] = "localhost"; Then to access multiple database: Code: <? But if you have just one database, then i suggest fill out the database informations in /application/config/database.php Code: $config['hostname'] = "localhost"; then use Code: <? this modell ![]() More examples: http://ellislab.com/codeigniter/user-gui...index.html
[eluser]grejsimojs[/eluser]
Wow thanks for taking your time to do that one! Very appreciated! I don't exactly understand everything in the code, such as the "\n\r". Also, do I have to load this model through the controller to make it work? I don't quite understand fully what just this model does. By the way, would you like to take this via mail instead?
[eluser]Adam Liszkai[/eluser]
![]() \n new line in console and in the rendered source code \r new line in OSX console and in the OSX rendered source code |
Welcome Guest, Not a member yet? Register Sign In |