Problème errer avec les class

Résolu
Denzel68 Messages postés 44 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 10 décembre 2019 - 18 déc. 2012 à 00:13
Denzel68 Messages postés 44 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 10 décembre 2019 - 18 déc. 2012 à 15:49
Bonjour,

Voila je suis pas très bon pour la création de class donc me voila confronter a une errer la voici :


voici le code php :
<?php
class SggCms {
  /**
   * variable de connection.
   *
   * @var string
   */
  public $sggconnect;
  /**
   * variable du cms.
   *
   * @var string
   */
  public $sggcms;

  function connect() {
    global $sggconnect;
    $database = mysql_connect($sggconnect['host'], $sggconnect['user'], $sggconnect['password']) or die ("
Error ! Database connexion failed
Check your user's name/password
");
    $connect = mysql_select_db($sggconnect['database'], $database) or die ("
Error ! Database connexion failed
Check your database's name
");
  }
  
  function SggCms($sggcms) {
    global $sggconnect;
    $this->SggCms['prefix'] = $sggconnect['prefix'];
    $sql_conf = mysql_query("SELECT name, value FROM " . $this->SggCms['prefix'] . "_config");
    while ($data_conf mysql_fetch_array($sql_conf)) $sggcms[$data_conf['name']] htmlentities($data_conf['value'], ENT_NOQUOTES);
    unset($sql_conf, $data_conf);

    $this->SggCms['footermessage'] = html_entity_decode($this->SggCms['footermessage']);
  }
}
?>

Et voici le code utiliser pour les test :
<?php
include 'conf.inc.php';
include 'Includes/function.php';

$test = new SggCms;
$test->connect();
echo $test->SggCms['prefix'];
echo $test->SggCms['title'];
?>

2 réponses

Denzel68 Messages postés 44 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 10 décembre 2019
18 déc. 2012 à 15:49
Problème résolu en faite il falais enlever l'argument($sggcms):
avent :
<?php
class SggCms {
  /**
   * variable de connection.
   *
   * @var string
   */
  public $sggconnect;
  /**
   * variable du cms.
   *
   * @var string
   */
  public $sggcms;

  function connect() {
    global $sggconnect;
    $database =  mysql_connect($sggconnect['host'], $sggconnect['user'], $sggconnect['password']) or die ("
Error ! Database connexion failed
Check your user's name/password
");
    $connect = mysql_select_db($sggconnect['database'], $database) or die ("
Error ! Database connexion failed
Check your database's name
");
  }
  
  function SggCms( $sggcms ) {
    global $sggconnect;
    
    $this->connect();

    $this->SggCms['prefix']  = $sggconnect['prefix'];
    $sql_conf = mysql_query("SELECT name, value FROM " . $this->SggCms['prefix'] . "_config");
    while ($data_conf mysql_fetch_array($sql_conf)) $this->SggCms[$data_conf['name']] htmlentities($data_conf['value'], ENT_NOQUOTES);
    unset($sql_conf, $data_conf);

    $this->SggCms['footermessage'] = html_entity_decode($this->SggCms['footermessage']);
  }
}
?>

âpre :
<?php
class SggCms {
  /**
   * variable de connection.
   *
   * @var string
   */
  public $sggconnect;
  /**
   * variable du cms.
   *
   * @var string
   */
  public $sggcms;

  function connect() {
    global $sggconnect;
    $database = mysql_connect($sggconnect['host'], $sggconnect['user'], $sggconnect['password']) or die ("
Error ! Database connexion failed
Check your user's name/password
");
    $connect = mysql_select_db($sggconnect['database'], $database) or die ("
Error ! Database connexion failed
Check your database's name
");
  }
  
  function SggCms() {
    global $sggconnect;
    
    $this->connect();

    $this->SggCms['prefix'] = $sggconnect['prefix'];
    $sql_conf = mysql_query("SELECT name, value FROM " . $this->SggCms['prefix'] . "_config");
    while ($data_conf mysql_fetch_array($sql_conf)) $this->SggCms[$data_conf['name']] htmlentities($data_conf['value'], ENT_NOQUOTES);
    unset($sql_conf, $data_conf);

    $this->SggCms['footermessage'] = html_entity_decode($this->SggCms['footermessage']);
  }
}
?>
3
Denzel68 Messages postés 44 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 10 décembre 2019
18 déc. 2012 à 11:00
Bonjour,

Voila je résolu un de mes problème (Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\SggCms\Includes\function.php on line 29)


Voici le nouveaux code :
Class :
<?php
class SggCms {
  /**
   * variable de connection.
   *
   * @var string
   */
  public $sggconnect;
  /**
   * variable du cms.
   *
   * @var string
   */
  public $sggcms;

  function connect() {
    global $sggconnect;
    $database = mysql_connect($sggconnect['host'], $sggconnect['user'], $sggconnect['password']) or die ("
Error ! Database connexion failed
Check your user's name/password
");
    $connect = mysql_select_db($sggconnect['database'], $database) or die ("
Error ! Database connexion failed
Check your database's name
");
  }
  
  function SggCms($sggcms) {
    global $sggconnect;
    
    $this->connect();

    $this->SggCms['prefix'] = $sggconnect['prefix'];
    $sql_conf = mysql_query("SELECT name, value FROM " . $this->SggCms['prefix'] . "_config");
    while ($data_conf mysql_fetch_array($sql_conf)) $this->SggCms[$data_conf['name']] htmlentities($data_conf['value'], ENT_NOQUOTES);
    unset($sql_conf, $data_conf);

    $this->SggCms['footermessage'] = html_entity_decode($this->SggCms['footermessage']);
  }
}
?>

et la page de test :
<?php
include 'conf.inc.php';
include 'Includes/function.php';

$test = new SggCms;
$test->connect();
echo $test->SggCms['prefix'] . "
";


if ($test->SggCms['desc'] != "")  $lol = " - " . $test->SggCms['desc'];
echo "<title>" . $test->SggCms['title'], $lol . "</title>";

echo $test->SggCms['title'], $lol . "

";

echo $test->SggCms['footermessage'];

?>


Merci a tout seul qui veulent bien m'aider
0
Rejoignez-nous