Hi,
* Martin Defeche <martin.defeche@stripped> [090814 22:09]:
> Hello,
>
> I would like to know if there is way to give the password to connect to the
> database when running the program instead of writing it in the source code.
>
> In fact, the database is local and the user should be root in order to make
> modification and I want my program to be portable.
In this sort of case I would usually have the program read the users
.my.cnf file.
mysqlpp::Connection c( "somedatabase" );
using the above the users .my.cnf file (/root/.my.cnf since you
specify the user will be root) will be read to obtain the
password.
Or you could specify some other location for the file as follows:
mysqlpp::Connection::set_option( new mysqlpp::ReadDefaultFileOption("/foo/bar/my.cnf" ) );
mysqlpp::Connection c( "somedatabase" );
For information on the .my.cnf file please refer to the standard mysql
client documentation.
Nick.