Écriture impossible

Petit nouveau ! | 1 Messages

31 janv. 2022, 14:58

Bonjour,
J'ai essayé d'upgrader mon framework de php5.6 à php7, le problème c'est que l'écriture de la base de donné ne fonctionne plus.
Voici le code de la class :

Code : Tout sélectionner

<?php class Database { public $address = "default"; public $username = "default"; public $password = "root"; public $dbname = "default"; public $port = "3306"; public $NULL; function __construct( String $NULL = NULL ) { $this->NULL = $NULL; } } class Module { protected $messages = array(); protected function AddDiagnostic(bool $success, string $msg) { array_push($this->messages, array($success, $msg)); } protected function FlushDiagnostics() { $this->messages = array(); } public function DisplayDiagnostics() { ?> <style> .mfdiagnostic_banner { background-color: orangered; width: 100%; height: 50px; } .mfdiagnostic_background{ background-color: white; width: 100%; } .mfdiagnostic_error { background-color: red; width: 100%; } .mfdiagnostic_success { background-color: green; width: 100%; } </style> <h1 class="mfdiagnostic_banner">MF Module Diagnostics</h1> <div class="mfdiagnostic_background"> <?php foreach ($this->messages as $item) { if ($item[0]) { ?> <p class="mfdiagnostic_success"> <?php echo $item[1]; ?> </p> <?php } else { ?> <p class="mfdiagnostic_error"> <?php echo $item[1]; ?> </p> <?php } } ?> </div> <div class="mfdiagnostic_banner"> Debug info flushed... </div> <?php $this->FlushDiagnostics(); } } class DatabaseCtrl extends Module { private $db; private $link; private $last_insert = -1; function __construct(Database $database) { $this->db = $database; $this->connect(); } public function __get($item) { if ('link' === $item) return ($this->link); else if ('last_insert' === $item) return ($this->last_insert); else $this->AddDiagnostic(false, "Error: Bad access to $item..."); } public function connect() { $db = $this->db; if ($this->link == false) { if (!($this->link = mysqli_connect($db->address, $db->username, $db->password, $db->dbname, $db->port))) { $this->AddDiagnostic(false, "Error: Failed to connect to mysqli..."); $this->AddDiagnostic(false, "Errno: " . mysqli_connect_errno()); $this->AddDiagnostic(false, "Error: " . mysqli_connect_error()); } else $this->AddDiagnostic(true, "Success: Connection to database successful!"); } else $this->AddDiagnostic(false, "Warning: Database already running..."); } public function query(string $query, string $argtype = "", ...$args) { $this->last_insert = -1; if ($this->link === FALSE) $this->connect(); if (!($stmt = mysqli_prepare($this->link, $query))) { $this->AddDiagnostic(false, "ERROR: Failed to prepare query..."); $this->AddDiagnostic(false, mysqli_errno($this->link)); $this->AddDiagnostic(false, mysqli_error($this->link)); return (NULL); } else $this->AddDiagnostic(true, "Query prepared!"); if ($argtype != "" && !(mysqli_stmt_bind_param($stmt, $argtype, ...$args))) { $this->AddDiagnostic(false, "ERROR: Failed to bind parameters to query..."); $this->AddDiagnostic(false, "Errno: " . mysqli_stmt_errno($stmt)); $this->AddDiagnostic(false, "Error: " . mysqli_stmt_error($stmt)); return (NULL); } else $this->AddDiagnostic(true, "Query parameters bound!"); if (!(mysqli_stmt_execute($stmt))) { $this->AddDiagnostic(false, "Error: Failed to execute query..."); $this->AddDiagnostic(false, "Errno: " . mysqli_stmt_errno($stmt)); $this->AddDiagnostic(false, "Error: " . mysqli_stmt_error($stmt)); } else $this->AddDiagnostic(true, "Query succesful!"); $res = mysqli_stmt_get_result($stmt); $this->last_insert = $stmt->insert_id; mysqli_stmt_close($stmt); return ($res); } public function longQuery(string $query, string $argtype = "", ...$args) { $this->last_insert = -1; if ($this->link === FALSE) $this->connect(); if (!($stmt = mysqli_prepare($this->link, $query))) { $this->AddDiagnostic(false, "ERROR: Failed to prepare query..."); $this->AddDiagnostic(false, mysqli_errno($this->link)); $this->AddDiagnostic(false, mysqli_error($this->link)); return (NULL); } else $this->AddDiagnostic(true, "Query prepared!"); $tmpArgs = $args; foreach ($tmpArgs as $key => $value) { if ($argtype[$key] == "b") $tmpArgs[$key] = NULL; } if (!(mysqli_stmt_bind_param($stmt, $argtype, ...$tmpArgs)) && $argtype != "") { $this->AddDiagnostic(false, "ERROR: Failed to bind parameters to query..."); $this->AddDiagnostic(false, "Errno: " . mysqli_stmt_errno($stmt)); $this->AddDiagnostic(false, "Error: " . mysqli_stmt_error($stmt)); return (NULL); } else $this->AddDiagnostic(true, "Query parameters bound!"); foreach ($args as $key => $value) { if ($argtype[$key] == "b") mysqli_stmt_send_long_data($stmt, $key, $value); } if (!(mysqli_stmt_execute($stmt))) { $this->AddDiagnostic(false, "Error: Failed to execute query..."); $this->AddDiagnostic(false, "Errno: " . mysqli_stmt_errno($stmt)); $this->AddDiagnostic(false, "Error: " . mysqli_stmt_error($stmt)); } else $this->AddDiagnostic(true, "Query succesful!"); $res = mysqli_stmt_get_result($stmt); $this->last_insert = $stmt->insert_id; mysqli_stmt_close($stmt); return ($res); } }
Oui, j'utilise mysqli #-o Avez-vous une idée d'où peut venir le problème ?
Merci d'avance ![/color]

Avatar du membre
Administrateur PHPfrance
Administrateur PHPfrance | 9782 Messages

31 janv. 2022, 19:04

Sans message d'erreur, difficile de t'aider...
Tu as regardé dans les logs ?
Quand tout le reste a échoué, lisez le mode d'emploi...

Avatar du membre
Petit nouveau ! | 4 Messages

02 févr. 2022, 16:00

Bonjour, il doit y avoir un message d'erreur pour préciser également le problème; sinon on ne peut pas le résoudre exactement.
Vérifiez-bien et postez le message d'erreur si tu le trouves.