Mysql et php 7 les classes
Bonjour,
J'ai une classes assez vieille et php me dit : Methods with the same name as their class will not be constructors in a future version of PHP; parameters has a deprecated constructor
Que dois je faire, voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| class parameters
{
var $values ='';
function parameters()
{
$this->load();
} // constructor
function load()
{
global $db;
$sql = "select id, value from parameters where session like 'O'";
// $sql = "select id, value from parameters where session = 'O'";
$c = $db->Select($sql,'');
while ($p = $c->fetch_object()) { $this->values[$p->id] = $p->value; }
// while ($p = mysql_fetch_object($c)) { $this->values[$p->id] = $p->value; }
$this->registered();
}
function get($id)
{
global $db;
if(!isset($this->values[$id])) {
// $v = $this->values[$id];
// if ($v == '')
// {
$sql = "select id, value from parameters where id = '$id'";
$p = $db->SelectOne($sql);
if (!$p) {
return false;
} else {
$this->values[$p->id] = $p->value; return $p->value;
$this->registered();
}
} else {
$v = $this->values[$id];
return $v;
}
}
function registered()
{
global $_sess_parameters;
$_sess_parameters = serialize($this);
// session_register("_sess_parameters");
$_SESSION['_sess_parameters']=$_sess_parameters;
}
function unregistered()
{
$this->values = null;
// session_unregister("_sess_parameters");
unset($_SESSION['_sess_parameters']);
}
} // class |
merci
Mysql et php7 les classes
Merci
par contre j'en ai un autre où c'est galère :
Methods with the same name as their class will not be constructors in a future version of PHP; database has a deprecated
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| class database_1 {
// var $dbh;
// var $db;
// var $cursor;
// var $nbrows;
// var $row;
function __construct($dbh, $db, $cursor,$nbrows,$row ) {
$this->dbh = $dbh;
$this->db = $db;
$this->cursor = $cursor;
$this->nbrows = $nbrows;
$this->row = $row;
}
function database($host,$user,$pass,$name) {
$this->dbh = mysqli_connect($host,$user,$pass);
//$this->dbh = mysql_pconnect($host,$user,$pass);
if (!$this->dbh) { die($host."___".$user."_____Server connexion failed");}
$this->dbh->query("SET NAMES 'latin1'");
if (!$this->select_db($name)) {
die($name." DB connexion failed ");
return false;
}
} // constructeur
function select_db($db) {
// Selectionne la database à utiliser. Si le paramètre de la fonction select est
// passé à la fonction database la variable de class sera mise à jour.
if (!empty($db)) $this->db = $db;
if (!$this->dbh->select_db($this->db)) {
// if (!mysql_select_db($this->db)) {
$this->last_error = mysql_error();
return false;
}
return true;
}
function Query($sql,$action) {
$this->nbrows = -1;
if (!$this->cursor = mysqli_query($this->dbh,$sql))
{
if ($action == 'no_error') {echo mysql_error();'<br>'; return false;}
else {die("[".$sql."] : ".mysql_error());}
}
$query_type = array("insert","delete","update");
// loop through the above array
foreach ( $query_type as $word ) {
// This is true if the query starts with insert, delete or update
if ( preg_match("/$word /i",$sql) ) { $this->nbrows = mysqli_affected_rows($this->dbh); }
}
return $this->nbrows;
} // Query
function Select($sql) {
// if (!$this->cursor = mysql_query($sql,$this->dbh)) { die("[".$sql."] : ".mysql_error()); }
if (!$this->cursor = mysqli_query($this->dbh,$sql)) { die("[".$sql."] : ".mysql_error()); }
$this->nbrows = $this->cursor->num_rows;
return $this->cursor;
} // Select
function SelectOne($sql) {
$this->Select($sql);
if ($this->nbrows == 1) { $this->row = mysqli_fetch_object($this->cursor); }
else { $this->row = false; }
return $this->row;
}
// SelectOne
function fetchObject() {
if (!$this->cursor) return false;
$this->row = $this->cursor->fetch_object();
return $this->row;
}
function insertid() {
if (!empty($db)) $this->db = $db;
if (!$this->dbh->select_db($this->db)) {
$this->last_error = mysql_error();
return false;
}
return (mysqli_insert_id($this->dbh));
}
} // class |