Location: PHPKode > projects > Pnyx : des lections virtuelles! > pnyx1.0.1/croquis/classes/accesbd.php
<? 
	#########################################################################################
	# Croquis en ligne, pour réaliser la pancarte dans Pnyx									#
	# Auteur : Sébastien Tremblay, hide@address.com										#
	# 																						#
	# Pnyx - une application Web (PHP/MySQL) d'élections virtuelles conçue pour	des	élèves	#
	# du primaire et du secondaire, dans lequel ils sont amenés à faire des	propositions	#
	# en ligne et voter pour leur favorite, sous la supervision d'un enseignant.			#
	#																						#
    # Copyright (C) <2008 - 2009>															#
	# <Service national du RÉCIT de l'univers social de la Commission scolaire de la		#
	# Pointe-de-l'Île>																		#
	#																						#
	# 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.	#
	# 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 as the file LICENSE.txt; if not, please see 									#
	# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.									#
	# 																						#
	# Service national du RÉCIT de l'univers social											#
	# http://www.recitus.qc.ca																#
	# Contact e-mail : steve-hide@address.com												#
	#########################################################################################

include_once(file_exists("constante.php")? "constante.php" : "../constante.php"); ?>
<?

class AccesBD
{
    var $m_Host      = ADD_SERVEUR_BD;
    var $m_Database  = DATABASE;
    var $m_User      = USER_NAME;
    var $m_Password  = PASSWORD;
    var $m_Link_ID   = 0;
    var $m_Query_ID  = 0;
    var $m_Record    = array();
    var $m_NoErreur  = 0;
    var $m_MsgErreur = "";


    function AccesBD($Host = "", $Database = "", $User = "", $Password = "")
    {
        $this->m_Host     = ($Host == "")     ? $this->m_Host     : $Host;
        $this->m_Database = ($Database == "") ? $this->m_Database : $Database;
        $this->m_User     = ($User == "")     ? $this->m_User     : $User;
        $this->m_Password = ($Password == "") ? $this->m_Password : $Password;
    }

    function Connect() // établit une connection à la base de donnée
    {
        $this->SetErreur(0, "");
        $ValeurRetour = 0;

        if ($this->m_Link_ID == 0)
        {
            $this->m_Link_ID = @mySql_connect($this->m_Host, $this->m_User, $this->m_Password);

            if (!$this->m_Link_ID)
            {
                $this->SetErreur(1, "La connection à la base de données a échouée.");
            }
            else
            {
                if (!@mysql_select_db($this->m_Database,$this->m_Link_ID))
                {
                    $this->SetErreur(2, "L'utilisation de la database a échouée.<br>");
                }
            }
        }

        $ValeurRetour = $this->m_Link_ID;

        return $ValeurRetour;
    }

    function Libere()
    {
        @mysql_free_result($this->m_Query_ID);
        $this->m_Query_ID = 0;
    }

    function Requete($Query_String)
    {
        $this->SetErreur(0, "");
        $ValeurRetour = 0;

        if ($Query_String == "")
        {
            $this->SetErreur(3, "Format de requete incorrect");
        }
        else
        {
            if (!$this->m_Link_ID)
            {
                $this->SetErreur(4, "Aucune connexion active");
            }
            else
            {
                $this->m_Query_ID  = @mysql_query($Query_String,$this->m_Link_ID);

                if (!$this->m_Query_ID)
                {
                    $this->SetErreur(5, "Format de requete incorrect");
                }
            }
        }

        $ValeurRetour = $this->m_Query_ID;

        return $ValeurRetour;
    }

    function NextRow()
    {
        $this->SetErreur(0, "");
        $ValeurRetour = 0;

        if (!$this->m_Query_ID)
        {
            $this->SetErreur(6, "fetch_array est appelée sans requète.");
        }
        else
        {
            $this->m_Record = @mysql_fetch_array($this->m_Query_ID);
        }

        $ValeurRetour = $this->m_Record;

        return $ValeurRetour;
    }

    function SetErreur($noErr, $MsgErr)
    {
        $this->m_NoErreur  = $noErr;
        $this->m_MsgErreur = $MsgErr;
    }

    function ProchaineClef($Table, $Clef)
    {
        $ValeurRetour = 0;

        $oBDTmp = new AccesBD();
        $oBDTmp->Connect();

        $oBDTmp->Requete("select ".$Clef." from ".$Table);

        for ($i = 1; $i <= $oBDTmp->GetNbRows(); $i++)
        {
            $oBDTmp->NextRow();
            if ($ValeurRetour == 0)
            {
                if ($i < $oBDTmp->GetFromRow($Clef))
                    $ValeurRetour = $i;
            }
        }

        return ($ValeurRetour == 0) ? ($oBDTmp->GetNbRows()+1) : $ValeurRetour;
    }

    function GetNbRows()           { return @mysql_num_rows($this->m_Query_ID); }

    function GetNbFields()         { return @mysql_num_fields($this->m_Query_ID); }

    function GetFromRow($champ)    { return $this->m_Record[strtolower($champ)]; }

    function GetNoErreur()         { return $this->m_NoErreur; }

    function GetMsgErreur()        { return $this->m_MsgErreur; }
}
?>
Return current item: Pnyx : des lections virtuelles!