DB backup tool, parameters

Notice: This thread is very old.
pistols
Member | 26
+
0
-

Hi there, please advice, I am currently preparing an on demand backup of the db my nette app works on. Unfortunetally my hosting doesn't allow any fancy tools so i will need to do it via php

I am thinking of using this: dg/MySQL-dump

The object needs a mysqli object to be constructed. I want to ask you, what is the best practice for converting a nette\database\connection to mysqli?

Should I really manually parse the dsn of the connection? and (stupid question follows) how do I retrieve the username and password from the nette\database\connection object?

Thanks in advance

bazo
Member | 620
+
0
-

that's not possible as nette database uses pdo and not mysqli. you will need to create a second connection through mysqli

pistols
Member | 26
+
0
-

Ok, I thought so. But what still bothers me (shame on me) is that I cannot extract the username, password and dns from the \Nette\Database\Connection object. I pass the database to my model, but the params of the connection are private. could you please advice how to? I am expecting something like $this->database->connection->params[0]. But thats not it.

Thanks a lot

Casper
Member | 253
+
+2
-

You can always do this:

parameters:
        database:
                 host: 127.0.0.1
                 username: ***
                 password: ***
                 scheme: ***

services:
        - MySQLDump
        - mysqli(
                %database.host%,
                %database.username%,
                %database.password%,
                %database.scheme%
        )
bazo
Member | 620
+
0
-

why would you do that? the credentials are stored in config as parameters. right? at least i hope so. your method is an atrocity

pistols
Member | 26
+
0
-

Yes, thats the approach I understand :). But I have still some fundamental unknowledge :)

I dont want to define my DB parameters again, but use the ones I have already defined under

development:
	nette:
		database:
			dsn: sdfsdfsdf
			user: sdkl
			pass: sdfsg

OR

production:
	nette:
		database:
			dsn: hkhjhjk
			user: hjk
			pass: hjk

according to the current scope (on production use the production credentials etc..).

Just to clarify what i need and it doesnt work is this:

services:
        - MySQLDump
        - mysqli(
                %nette.database.host%,
                %nette.database.username%,
                %nette.database.password%,
                %nette.database.scheme%
        )

Last edited by pistols (2014-09-19 10:01)

petr.pavel
Member | 535
+
0
-

I think @pistols missed that in @Casper's sample code, the login credentials were stored in parameters/database – not in nette/database as @pistols' later code shows.

pistols
Member | 26
+
0
-

Ok please to close this issue, can you please advice how to pass the actual db settings into a service?

Thanks

petr.pavel
Member | 535
+
0
-

But @Casper already showed you. %database.host% etc. What did you not understand about it?

pistols
Member | 26
+
0
-

petr: I dont want to create a new section under parameters to keep my credentials. I have already defined them in config.local.neon

development:
	nette:
		database:
			dsn: ...

and

production:
	nette:
		database:
			dsn: ....

and thats the place from where I want to take them… (in other words I don't want to define the same information in two separate places)

Last edited by pistols (2014-09-19 10:48)