NTDB definition in 2.3 dev

Notice: This thread is very old.
petr.pavel
Member | 535
+
+1
-

Hi guys, I can't get Nette dev to connect to database that I specify in config.neon.

Old method:

nette:
	database:
		default:
			dsn: 'mysql:host=localhost;dbname=mydbname'
			user: mydbuser
			password: supersecret

dies with Configuration section 'nette.database' is deprecated, move it to section 'database'.

New method described in documentation doesn't work either though:

database:
	default:
		dsn: 'mysql:host=localhost;dbname=mydbname'
		user: mydbuser
		password: supersecret

gives Unknown configuration option database.default.default.

It seems that “default:” isn't recognized. When I change it to anything else, the error changes to match the changed name:

database:
	ahoj:
		dsn: 'mysql:host=localhost;dbname=mydbname'
		user: mydbuser
		password: supersecret

Unknown configuration option database.default.ahoj.

I even tried removing the connection name:

database:
	dsn: 'mysql:host=localhost;dbname=mydbname'
	user: mydbuser
	password: supersecret

Nette doesn't die with an error now however, it simply ignores the whole thing, trying to connect anonymously to db test.

	/**
	 * @return Nette\Database\Connection
	 */
	public function createServiceDatabase__default()
	{
		$service = new Nette\Database\Connection('mysql:host=127.0.0.1;dbname=test', NULL, NULL, array('lazy' => TRUE));
		$this->getService('tracy.blueScreen')->addPanel('Nette\Bridges\DatabaseTracy\ConnectionPanel::renderException');
		Nette\Database\Helpers::createDebugPanel($service, TRUE, 'default');
		return $service;
	}

I pass Nette\Database\Context $db to my model and then I call $db->table('mytable'); Not sure if it's related.

Any idea what's wrong?

David Grudl
Nette Core | 8218
+
+3
-

Seems like wrong format of config file.

Configuration section 'nette.database' is deprecated, move it to section 'database' throws when you have both nette.database and database sections. So check config.neon and config.local.neon and use only one way.

petr.pavel
Member | 535
+
0
-

Holy Jesus on a Stick! [Debra Morgan] It never occurred to me to suspect config.local.neon of a freshly installed sandbox. Thanks @DavidGrudl. Not sure why it's set to connect to localhost test db.

Last edited by petr.pavel (2015-02-17 17:25)

Zemistr
Member | 2
+
0
-

Thank's David, you saved my life :D