dev - change to connect db
This commit is contained in:
parent
20d1f2af26
commit
8170066056
16
src/connect-db.php
Normal file
16
src/connect-db.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
function connexionDB($host,$db,$user,$pass) {
|
||||||
|
$dsn = "mysql:host=$host;dbname=$db;charset=UTF8";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = new PDO($dsn, $user, $pass, [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Mode erreur
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Mode de récupération
|
||||||
|
PDO::ATTR_EMULATE_PREPARES => false, // Préparation réelle des requêtes
|
||||||
|
]);
|
||||||
|
return $pdo;
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Erreur de connexion : " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once 'config.php';
|
|
||||||
function connect($host, $db, $user, $password)
|
|
||||||
{
|
|
||||||
$dsn = "mysql:host=$host;dbname=$db;charset=UTF8";
|
|
||||||
|
|
||||||
try {
|
|
||||||
$options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
|
|
||||||
|
|
||||||
return new PDO($dsn, $user, $password, $options);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
die($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'config.php';
|
require_once 'config.php';
|
||||||
// conection db
|
// conection db
|
||||||
$conn = require 'connect.php';
|
require_once 'connect-db.php';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
@ -17,6 +18,8 @@ $conn = require 'connect.php';
|
|||||||
<?php echo $site_copyright; echo "<hr>"; ?>
|
<?php echo $site_copyright; echo "<hr>"; ?>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$conn=connexionDB($host, $db, $user, $password);
|
||||||
|
//echo $conn;
|
||||||
// sql to create table
|
// sql to create table
|
||||||
$sql = "CREATE TABLE IF NOT EXISTS $table (
|
$sql = "CREATE TABLE IF NOT EXISTS $table (
|
||||||
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||||
@ -26,7 +29,6 @@ email VARCHAR(50) UNIQUE,
|
|||||||
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
mod_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
mod_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
)";
|
)";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$conn->query($sql);
|
$conn->query($sql);
|
||||||
echo "<p>Table <b>".$table."</b> created successfully</p>";
|
echo "<p>Table <b>".$table."</b> created successfully</p>";
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'config.php';
|
require_once 'config.php';
|
||||||
// conection db
|
// conection db
|
||||||
$conn = require 'connect.php';
|
require_once 'connect-db.php';
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
@ -16,6 +16,10 @@ $conn = require 'connect.php';
|
|||||||
<h2><?php echo $db_site_title ?></h2>
|
<h2><?php echo $db_site_title ?></h2>
|
||||||
<?php echo $site_copyright; echo "<hr>"; ?>
|
<?php echo $site_copyright; echo "<hr>"; ?>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// connect to DB
|
||||||
|
$conn=connexionDB($host, $db, $user, $password);
|
||||||
|
|
||||||
// sql to create table
|
// sql to create table
|
||||||
$sql = "DROP TABLE IF EXISTS $table;";
|
$sql = "DROP TABLE IF EXISTS $table;";
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
|
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
|
||||||
require_once 'config.php';
|
require_once 'config.php';
|
||||||
// conection db
|
// conection db
|
||||||
$conn=require 'connect.php';
|
require_once 'connect-db.php';
|
||||||
|
$conn=connexionDB($host, $db, $user, $password);
|
||||||
|
|
||||||
$defaultAction='add';
|
$defaultAction='add';
|
||||||
$defaultModCre=false; // display or not created/modified date
|
$defaultModCre=false; // display or not created/modified date
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user