Codeigniter - Installation script

Asked

Viewed 277 times

1

I created an installer for my system it installs normal, but before finishing the installation the error occurs

Error Number: 1046

No database selected

CREATE TABLE IF NOT EXISTS `auditoria` ( `id` int(11) NOT NULL AUTO_INCREMENT, 
`usuario` varchar(45) NOT NULL, 
`data_hora` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
`operacao` varchar(45) NOT NULL, `query` text NOT NULL, 
`observacao` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Filename: C:\wamp\www\ehpcms\system\database\DB_driver.php

Line Number: 330

Follow my controller install.php

http://pastebin.com/7W5YduaG

  • I suggest you improve your script. What you are is called DB Migration (Application create DB structure). There are some ways to do it, but the wrong way to do it is from the controller.

  • @Can you give me a hand then? Or at least help me to fix this file even, I’m starting now, so for didactic purposes already helps me.

  • my guess is that the moment the controller runs, Codeigniter loads the information from the config files and after you create the new file with the configs, it has not yet been loaded by the framework. That explains him spinning the second time.

  • One approach you can use is to split the installation into two Steps: one first for the configs and one next for the tables.

  • Another suggestion, even though it is easy to use the framework, try to learn how to do some things by hand, pure PHP. Didactically you have more to gain and will know if face the difference between write_file of the IC and file_put_contents of PHP

  • I share the same opinion. 1º log in with the data, submit the form and create the files, and then run to create the tables

  • A place to start: http://br.phptherightway.com/ :)

  • I will first try to submit the form before and then create the tables, let’s see if I can

Show 3 more comments

1 answer

1

Error informs that Driver did not find DB.
You need to change the DB in your file application\config\database.

Change the lines below:

$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
  • But this data should be inserted dynamically, in the system installation, and not manually, understand?

  • But if you want to create a table, you need to inform the database...

  • In my controller, I’m passing the database variable to fill in.

  • If I try to install the system 1 time it gives the error, not the second time. If I’m not understanding you explain me please

  • I think your config file is being rewritten. The second time you run it $this->input->post( ... ). See the @gmsantos comment. Even if you have an installer for creating tables, nothing prevents you from keeping config with the Conn data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.