List:General Discussion« Previous MessageNext Message »
From:David T-G Date:March 23 2004 11:02am
Subject:Re: php script for new database and user
View as plain text  
Hash: SHA1

Lefty --

...and then BGLefty said...
% Is there a simple php script out there somewhere (or an example of how to do

It's a little bigger than "simple", but have you seen phpMyAdmin?

% it) to create a new database, username and password? I would like to have a
% form in a password protected folder on my web site and be able to fill in
% those three variables to create a new database on my installation of mysql
% on my home computer (be able to do this from my office or another computer).
% It seems like a simple enough thing to do but I have been unable to find any
% examples...

Indeed it should be.  Admittedly, I may be overlooking something since
I've created a user that can't get in, but we can edit this post when I'm
finally shown the problem :-)

So your script should run something like

  if ( not https )
    { redirect to https ; exit ; }

  if ( no or incorrect password )
    check $_POST for password input ;
    get password ;
    exit ;

  if ( $_POST['dbname'] && $_POST['dbuser'] && $_POST['dbpass'] )
      or die("Could not connect\n") ;
    mysql_query("create database {$_POST['dbname']}")
      or die("Could not create db\n") ;
    mysql_query("grant all privileges on {$_POST['dbname']}.* to
      {$_POST['dbuser']} identified by {$_POST['dbname']}
      with grant option")
      or die("Could not create user\n") ;
    mysql_query("flush privileges") ;
    { display input page ; exit ; }

(just from the top of my head, and without any real security checking
since you're the only who will use the script and you know better).  This
will ask for db name, db user, db pass and then connect as your root user
to attempt to create the database and then give the user permissions on
it (thereby creating the user record).

% Any help would be appreciated.
% Thanks,
% BGLefty


- -- 
David T-G                      * There is too much animal courage in 
(play) davidtg@stripped * society and not sufficient moral courage.
(work) davidtgwork@stripped  -- Mary Baker Eddy, "Science and Health"      Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

Version: GnuPG v1.2.4 (FreeBSD)

php script for new database and userBGLefty17 Mar
  • Re: php script for new database and userW. D.18 Mar
    • RE: php script for new database and userElly Wisata18 Mar
  • Re: php script for new database and userDavid T-G23 Mar
RE: php script for new database and userSWBT)18 Mar
  • Re: php script for new database and userBernd Tannenbaum18 Mar
Re: php script for new database and userjeffrey_n_Dyke18 Mar
  • Re: php script for new database and userElly Wisata18 Mar