No longer need to put the database server connection info in each page
This commit is contained in:
15
var/www/db_connection.php
Normal file
15
var/www/db_connection.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$db_server = "localhost";
|
||||
$db_name = "friendBook";
|
||||
$db_username = "web";
|
||||
$db_password = "Password456";
|
||||
|
||||
try{
|
||||
$db_connection = new PDO("mysql:host=$db_server;dbname=$db_name", $db_username, $db_password);
|
||||
$db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
}catch(PDOException $e){
|
||||
echo "PDOException: ".$e->getMessage();
|
||||
}catch(Exception $e){
|
||||
echo "Exception: ".$e->getMessage();
|
||||
}
|
||||
?>
|
||||
@@ -1,10 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$server = "localhost";
|
||||
$database = "friendBook";
|
||||
$username = "web";
|
||||
$password = "Password456";
|
||||
require 'db_connection.php';
|
||||
?>
|
||||
|
||||
<html>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_connection.php';
|
||||
|
||||
if (isset($_POST['Submit'])){
|
||||
$_SESSION['loginData'] = $_POST;
|
||||
|
||||
Reference in New Issue
Block a user