Subject | Re: fbird_add_user and fbird_service_attach (create db without isql, WORKS) |
---|---|
Author | Robert |
Post date | 2004-12-07T21:32:07Z |
I noticed an obvious bug, replace foreach loop with;
foreach ($userinfo as $user) {
if ($user['user_name']==strtoupper($dbuser)) {
$adduser=0;
break;
}
else
$adduser=1;
}
Still not very happy with that but it gets the job done (correctly)
for the time being.
--- In firebird-php@yahoogroups.com, "Robert" <falcatemoon@y...>
wrote:
foreach ($userinfo as $user) {
if ($user['user_name']==strtoupper($dbuser)) {
$adduser=0;
break;
}
else
$adduser=1;
}
Still not very happy with that but it gets the job done (correctly)
for the time being.
--- In firebird-php@yahoogroups.com, "Robert" <falcatemoon@y...>
wrote:
>wrote:
> --- In firebird-php@yahoogroups.com, Lester Caine <lester@l...>
> > Robert wrote:I'm
> >
> > > I was reading in the forum that with PHP5 you can create a
> database in
> > > a query statement has anyone have an example of working code?
> >
> > Not with Firebird.
> > I use the isql path for tikipro and build the database that way.
> You
> > need to be connected to a database before you can actually do any
> other
> > SQL, so unless you bounce of the security database, which I would
> not
> > recommend in php code, then you need a 'database less' way of
> creating it.
> >
> > --
> > Lester Caine
> > -----------------------------
> > L.S.Caine Electronic Services
>
> Actually I got everything working now without using isql at all here
> is my code that creates the user account and the DB without isql.
> using PHP5.0.l and yes this code works perfectly for me, I had to
> actually read the CVS to find all of this out.
>
> /* These are temporary values, that will only be used during install
> */
> $tmp_user = 'sysdba';
> $tmp_pass = 'masterykey';
> /* End of Temp */
>
> // These are params from my config file (Some are not used here)
> // Path where firebird Database will reside
> $data_path = "/data/";
> // Apache's Document root
> $http_path = "/wwwroot/htdocs/";
> // Name of program's root directory
> $doc_root = "challenge";
> // Databse Name used by program
> $dbname = "test";
> // Database host
> $dbhost = "localhost";
> // User Name used to connect to program database
> $dbuser = "phpadmin";
> // Password used to connect to program database
> $dbpass = "masterkey";
> // Recreate Database switch
> $recreatedb = 1;
> // Ensure db only gets created if needed
> $createdb=1;
>
> if(!($service=fbird_service_attach($dbhost,$tmp_user,$tmp_pass)))
> die('Unable to Connect to FireBird Serviec Manager!');
>
> If(!($userinfo=fbird_server_info($service,IBASE_SVC_GET_USERS)))
> die('Unable to Gather FireBird User information!');
>
> foreach ($userinfo as $user)
> $adduser = ($user['user_name']==strtoupper($dbuser)) ? 0 : 1;
>
> if ($adduser) {
> if(!fbird_add_user($service, $dbuser, $dbpass))
> die('Unable to add User!');
> }
> fbird_service_detach($service);
>
> $strconnect = "$dbhost:".$data_path.$dbname.".fdb";
>
> if ($db=fbird_connect($strconnect, $dbuser, $dbpass, 'ISO8859_1', 0,
> 1)) {
> if ($recreatedb) {
> if(!(fbird_drop_db($db)))
> die('Unable to Drop Database!');
> }
> else
> $createdb=0;
> fbird_close($db); // May not close may use to prep DB
> }
>
> if ($createdb) {
> $sql = "CREATE DATABASE '".$data_path.$dbname.".fdb'
> USER '$dbuser' PASSWORD '$dbpass'
> PAGE_SIZE 8192
> DEFAULT CHARACTER SET ISO8859_1; \n";
>
> if(!($db=fbird_query(IBASE_CREATE, $sql)))
> die('Unable to Create Database!');
>
> fbird_close($db); // May not close may use to prep DB
> echo "The database: $dbname, was created successfully.<br/>";
> }
>
> echo "Database Ready!"