t4newman Posted March 29, 2010 Share Posted March 29, 2010 Help. I need to write a php script that when a site is first uploaded and runs the home page checks if a database exists, and if not, asks for config data to create the database and save that data in a file on the server, to use from then on. Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/196852-checking-if-database-exists/ Share on other sites More sharing options...
ignace Posted March 29, 2010 Share Posted March 29, 2010 if (!mysql_select_db($databaseName)) { //database not present or no server (MySQL) connection } Quote Link to comment https://forums.phpfreaks.com/topic/196852-checking-if-database-exists/#findComment-1033479 Share on other sites More sharing options...
t4newman Posted March 29, 2010 Author Share Posted March 29, 2010 I'm trying to get the home page to redirect to prompt for config information if the database doesn't exist. <?php //Refer to config file/common functions include('utils.php'); $page4config = $htURL . $configpage; $databaseName = $dbName; if (!mysql_select_db($databaseName)) { //database not present or no server (MySQL) connection header("Location: $page4config"); exit(); } else { // db exists } ?> However, it errors with:- Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\xampp\ccn\index.php on line 6 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\xampp\htdocs\xampp\ccn\index.php on line 6 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\xampp\ccn\index.php:6) in C:\xampp\htdocs\xampp\ccn\index.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/196852-checking-if-database-exists/#findComment-1033500 Share on other sites More sharing options...
ignace Posted March 29, 2010 Share Posted March 29, 2010 I assumed you already created a connection to the database and you only wanted to verify if a certain database exists, NOT apparently. Use: $connection = mysql_connect($cfg['host'], $cfg['username'], $cfg['password']); if (!$connection) { header('Location: install/index.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/196852-checking-if-database-exists/#findComment-1033532 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.