mysqli::$connect_error

mysqli_connect_error

(PHP 5, PHP 7, PHP 8)

mysqli::$connect_error -- mysqli_connect_errorReturns a description of the last connection error

Descrizione

Stile orientato agli oggetti

Stile procedurale

mysqli_connect_error(): ?string

Returns the error message from the last connection attempt.

Elenco dei parametri

Questa funzione non contiene parametri.

Valori restituiti

A string that describes the error. null is returned if no error occurred.

Esempi

Example #1 $mysqli->connect_error example

Stile orientato agli oggetti

<?php

mysqli_report
(MYSQLI_REPORT_OFF);
/* @ is used to suppress warnings */
$mysqli = @new mysqli('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if (
$mysqli->connect_error) {
/* Use your preferred error logging method here */
error_log('Connection error: ' . $mysqli->connect_error);
}

Stile procedurale

<?php

mysqli_report
(MYSQLI_REPORT_OFF);
/* @ is used to suppress warnings */
$link = @mysqli_connect('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if (!
$link) {
/* Use your preferred error logging method here */
error_log('Connection error: ' . mysqli_connect_error());
}

Vedere anche:

add a note add a note

User Contributed Notes 1 note

up
-8
gejez at polyswarms dot com
6 years ago
<?php

   
class bDBresult {
        private
$result;
       
        public function
__construct($res) {
           
$this->result = $res;
        }

        public function
num_rows() {
            return
$this->result->num_rows;
        }

        public function
next_row() {
            return
$this->result->fetch_assoc();
        }
       
    }

    class
bDB {
        private static
$conf;
        private
$conn;

        public static function
set_conf_file($dbconf_path) {
           
self::$conf = parse_ini_file($dbconf_path); 
        }

        public function
__construct() {
           
$this->conn = new mysqli(
               
self::$conf['db.host.address'],
               
self::$conf['db.user.admin.name'],
               
self::$conf['db.user.admin.password'],
               
self::$conf['db.bibliotecando.name']
            );
        }

        public function
send_query($coms) {
            return new
bDBresult($this->conn->query($coms));
        }

    }

?>
To Top