Jump to content

Checking if database exists


t4newman

Recommended Posts

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.

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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');
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.