Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Commit

Permalink
paremmat virheilmoitukset, PDO näyttää tietokantakyselyiden virheet
Browse files Browse the repository at this point in the history
  • Loading branch information
kalleilv committed Apr 14, 2015
1 parent 3351356 commit 96ad192
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"require": {
"slim/slim": "2.*",
"twig/twig": "~1.5",
"raveren/kint": "v0.9"
"raveren/kint": "v0.9",
"zeuxisoo/slim-whoops": "0.3.0"
}
}
223 changes: 223 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require 'vendor/autoload.php';

$routes = new \Slim\Slim();
$routes->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware);

$routes->get('/tietokantayhteys', function(){
DB::test_connection();
Expand Down
11 changes: 7 additions & 4 deletions lib/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ public static function connection(){
}else{
$connection = new PDO($config['resource']);
}
// Asetetaan tietokannan kenttien koodaukseksi utf8
$connection->exec('SET NAMES UTF8');

// Asetetaan tietokannan kenttien koodaukseksi utf8
$connection->exec("set names utf8");

// Näytetään virheilmoitukset
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

} catch (PDOException $e) {
die('Virhe tietokantayhteydessä: ' . $e->getMessage());
die('Virhe tietokantayhteydessä tai tietokantakyselyssä: ' . $e->getMessage());
}

return $connection;
Expand Down

0 comments on commit 96ad192

Please sign in to comment.