Blog_IMIE/project/assets/php/functions.php
2019-02-18 15:05:33 +01:00

28 lines
601 B
PHP
Executable File

<?php
//function pour voir la fin d'un texte
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
function connect() {
$host = "127.0.0.1";
$db = "blog";
$user = "blog";
$pass = "blog";
$charset="utf8mb4";
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
try {
$pdo = new PDO($dsn, $user, $pass);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
return $pdo;
}