Jump to content

Checking if database exists


t4newman

Recommended Posts

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

 

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.