Lamez Posted November 18, 2007 Share Posted November 18, 2007 I am trying to make a database installer, when I mean when I say that is: instead of changing my config.php file manually, I want a php script to do it for me, and automatically add the tables I need, and automatically add an admin user to the database under the admin table, and I want to know how I can go about doing this? I think I can get the tables and adding the user, but how do I go about editing my config file? I need to add variables in my config file. Is there a way I can use a .sql file to add the tables, and users to the database through php? any help? -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/77807-database-installer/ Share on other sites More sharing options...
MadTechie Posted November 18, 2007 Share Posted November 18, 2007 write to the php file as you would any text file.. and to import an sql file you could use bigdump Quote Link to comment https://forums.phpfreaks.com/topic/77807-database-installer/#findComment-393842 Share on other sites More sharing options...
wildteen88 Posted November 18, 2007 Share Posted November 18, 2007 As for creating the config.php file automatically based on the information entered in the configuratioin form you can do this: <?php if(isset($_POST['submit'])) { $errors = null; foreach($_POST['config'] as $key => $value) { if(isset($_POST['config'][$key]) && empty($_POST['config'][$key])) { $field = str_replace(array('db', '_'), array('Database', ' '), $key); $errors[] = '<b>' . ucwords($field) . '</b> field left blank!'; } } if(is_array($errors)) { $error_msg = "Please correct the following errors:\n<ul>\n <li>" . implode("</li>\n <li>", $errors) . "</li>\n</ul>\n\n"; } else { $config = "<?php\n\n"; foreach($_POST['config'] as $key => $value) { $config .= '$'.$key .' = \'' . $value . "';\n"; } $config .= "\n?>"; // write configuration to config.php $handle = fopen('config.php', 'w'); // open fwrite($handle, $config); // write fclose($handle); // close echo 'config.php created:<br /><br />'; echo '<textarea name="" rows="10" cols="60">' . $config . '</textarea>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Database installer</title> </head> <body> <h1>Database Installer</h1> <?php if(isset($error_msg) && !empty($error_msg)) echo $error_msg; ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Database Infomation</legend> Hostname: <input type="text" name="config[db_hostname]" value="localhost" /><br /> Username: <input type="text" name="config[db_username]" /><br /> Password: <input type="text" name="config[db_password]" /><br /> Name: <input type="text" name="config[db_name]" /> </fieldset> <br /> <fieldset> <legend>Administrator Infomation</legend> Username: <input type="text" name="config[admin_username]" /><br /> Password: <input type="text" name="config[admin_password]" /> </fieldset> <br /> <input type="submit" name="submit" value="Setup Database" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/77807-database-installer/#findComment-393854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.