Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/databaser/
dbconnection.php
index.php
ovn_0/
ovn_1/
ovn_2/
ovn_3/
dbconnection.php
33 lines UTF-8 Windows (CRLF)
<!-- dbconnection.php -->
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$local = false; // HM det här måste vara false på labbservern
if($local){
$dbname = 'mindatabas'; //namnet på din lokala db här
$hostname = 'localhost';
$/* DB_USER, is removed and hidden for security reasons */ ;
$/* DB_PASSWORD, is removed and hidden for security reasons */ ;
}
else {
$dbname = 'harmol23';
$hostname = 'localhost';
$/* DB_USER, is removed and hidden for security reasons */ ;
$/* DB_PASSWORD, is removed and hidden for security reasons */ ;
}
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'");
try {
$dbconn = new PDO("mysql:host=$hostname;dbname=$dbname;", $/* DB_USER, is removed and hidden for security reasons */ ;
$dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
}
catch(PDOException $e){
// For debug purpose, shows all connection details
echo 'Connection failed: '.$e->getMessage()."<br />";
// Hide connection details.
//echo 'Could not connect to database.<br />');
}