Bonjour à tous !
Pour mon nouveau site, j'ai voulu passer le cap de xHTML à HTML5 et l'utilisation de PDO en PHP.
Mais voilà, alors que je commence à peine la connexion à la BDD, celle-ci m'embête déjà...
Voici mes codes :
index.php
Et le fichier fonctions.php :
Voilà, je ne comprends pas d'où vient le problème, et j'ai cette erreur :
Pour réaliser mes codes, je suis sous Fedora 16, avec un serveur Apache et j'utilise Netbeans 7.1.
Ne faites pas attention à la fonction sqlquery(), je ne l'ai pas encore mis à jour vers PDO.
Merci d'avance pour vos réponses !
Cordialement
Pour mon nouveau site, j'ai voulu passer le cap de xHTML à HTML5 et l'utilisation de PDO en PHP.
Mais voilà, alors que je commence à peine la connexion à la BDD, celle-ci m'embête déjà...
Voici mes codes :
index.php
<?php
/*
index.php
Version 1.0 - C2401
This program is free software; you can not redistribute it and/or modify
it under the terms of the Creative Commons BY-NC-ND.*/
/*
* Début du code source
*/
$debut = microtime(true);
session_start();
header('Content-type: text/html; charset=utf-8');
include('includes/config.php');
/*
* Inclusion de fonctions.php
* Connexion à la BDD
* Récupération de l'état du site
* Actualisation de la session...
*/
include('includes/fonctions.php');
//try{
connexionbdd();
$etat = en_ligne();
actualiser_session();
/*
* Fin actualisation de session...
*/
/*
* En-tête et titre de page
*/
$titre = 'Accueil';
include('includes/haut.php'); //contient le doctype, et début de head.
/*
* Fin entête et titre
*/
?>
<link rel="stylesheet" href="<?php echo ROOTPATH; ?>/styles/index.css" type="text/css" media="screen" />
<!--[if IE]>
<link rel="stylesheet" media="screen" type="text/css" href="styles/IE/index.css" />
<![endif]-->
</head>
<?php
include('includes/menu.php');
echo 'test';
?>
<?php
include('includes/bas.php');
?>
Et le fichier fonctions.php :
<?php
/*
fonctions.php
Version 1.0 - C2401
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
/*
* On inclut la page du traitement du BBCode
*/
include("includes/bbcode.php");
/*
* Fonction qui exclut tout bot du site. (Non-exhaustive).
*/
function bot()
{
if(empty($_SERVER['HTTP_USER_AGENT']) OR $_SERVER['HTTP_USER_AGENT'] == '' OR $_SERVER['HTTP_USER_AGENT'] == 'crawl')
{
header('Location: http://www.kekette.org');
}
}
/*
* Retourne la vraie adresse IP
*/
function get_ip()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else
$ip = $_SERVER['REMOTE_ADDR'];
return $ip;
}
/*
* Vérifie si le site est en ligne.
* Oui : On ne fait rien.
* Non : On redirige vers la page travaux.html
* Oui mais Admin : On ne fait rien.
*/
function en_ligne()
{
$retour = mysql_query('SELECT * FROM site_config WHERE config_nom="en_ligne"') or die(mysql_error());
$donnees = mysql_fetch_array($retour);
$etat = 1;
if(isset($_GET['admin']) AND $_GET['admin'] == 1)
$donnees['config_valeur'] = 1;
if($donnees['config_valeur'] == 0)
{
$etat = 4;
if(!isset($_SESSION['membre_niveau']))
{
$adresse = ROOTPATH . '/travaux.html';
header("Location: $adresse");
$etat = 2;
}
else
{
if($_SESSION['membre_niveau'] <= 1)
{
$adresse = ROOTPATH . '/travaux.html';
header("Location: $adresse");
$etat = 3;
}
if($_SESSION['membre_niveau'] >= 2)
$etat = 0;
}
}
return $etat;
}
/*
* Fonction permettant de réaliser toutes les requêtes SQL.
*/
/*
* Connexion à la base de données
*/
function connexionbdd(){
//include('admin/includes/mbdd.php');
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
//$bdd = new PDO('mysql:host='.$ABDD.';dbname='.$DB, $LOG, $MDP, $pdo_options);
try{
$bdd = new PDO('mysql:host=localhost;dbname=web1607_db1', 'web1607_u1', '****', $pdo_options);
}
catch (Exception $e){
die('Erreur : ' . $e->getMessage());
}
return $bdd;
}
/*
* Fonction pour réaliser les requêtes et réalise le mysql_fetch_array
*/
function sqlquery($requete)
{
$query = mysql_query($requete) or exit('Erreur SQL : '.mysql_error().' Ligne : '. __LINE__ .'.'); //requête
$query2 = mysql_fetch_assoc($query);
mysql_free_result($query);
$queries++;
return $query2;
}
?>
Voilà, je ne comprends pas d'où vient le problème, et j'ai cette erreur :
Access denied for user 'apache'@'localhost' (using password: NO)
Pour réaliser mes codes, je suis sous Fedora 16, avec un serveur Apache et j'utilise Netbeans 7.1.
Ne faites pas attention à la fonction sqlquery(), je ne l'ai pas encore mis à jour vers PDO.
Merci d'avance pour vos réponses !
Cordialement