• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] How to test if a database is connected

#1
I am having difficulty in trying to test if database has connected. 

I know that the database does not exist and would like the application to fail gracefully. 

When the database does not exist I would like to show download SQL database installation details.

Edit:      

PHP Code:
//============================================================
private function isConnected
(
  
string $dbName
)
bool
{
  $result FALSE;
    
  error_reporting
(0);  
    $link 
mysqli_connect("localhost""userName""passWord"$dbName);
  error_reporting(-1);

  $result = isset($link->errno) ;
  
  
return $result;   
}//


//============================================================
private function newDatabase
(
  
string $dbName
)
bool
{
  $result FALSE;
  # error_reporting(0);

  $conn   mysqli_connect("localhost""userName""passWord");
  $sql    'CREATE DATABASE ' $dbName ;
  $result $conn->query($sql);

  return $result;
}
//  

//============================================================
private function newTable
(
  
object $conn
  
string $dbName
  
string $table
)
bool
{
  $result FALSE;

  $sql file_get_contents(BASEURL .'assets/sql/' .$table .'.sql');
  $result $conn->query($sql);

  return $result TRUE;
}
//  

Next hurdle - create indexii Smile
download and make your system directory strict
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.