w3resource

PHP mysqli: connect_error() function

mysqli_connect_error() function / mysqli::$connect_error

The mysqli_connect_error() function / mysqli::$connect_error returns the error description from the last connection error, if any.

Syntax:

Object oriented style

string $mysqli->connect_error;

Procedural style

string mysqli_connect_error ( void )

Usage: Procedural style

mysqli_connect_error();

Return value:

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

Version: PHP 5, PHP 7

Example of object oriented style:

<?php
$mysqli = @new mysqli('localhost', 'user1', 'datasoft123', 'hr');

// Works as of PHP 5.2.9 and 5.3.0.
if ($mysqli->connect_error) {
    die('Connect Error: ' . $mysqli->connect_error);
}
?>

Example of procedural style:

<?php
$link = @mysqli_connect('localhost', 'user1', 'datasoft123', 'hr');

if (!$link) {
    die('Connect Error: ' . mysqli_connect_errno());
}
?>

Example:

<?php
$con=mysqli_connect("localhost","user1","datasoft123","hr");
// Check connection
if (!$con)
  {
  die("Connection error: " . mysqli_connect_errno());
  }
?>

Output:

Connection error: 0

See also

PHP Function Reference

Previous: connect_errno
Next: connect



Follow us on Facebook and Twitter for latest update.

PHP: Tips of the Day

PHP - how to create a newline character?

Only double quoted strings interpret the escape sequences \r and \n as '0x0D' and '0x0A' respectively, so you want:

"\r\n"

Single quoted strings, on the other hand, only know the escape sequences \\ and \'.

So unless you concatenate the single quoted string with a line break generated elsewhere (e. g., using double quoted string "\r\n" or using chr function chr(0x0D).chr(0x0A)), the only other way to have a line break within a single quoted string is to literally type it with your editor:

$s = 'some text before the line break
some text after';

Make sure to check your editor for its line break settings if you require some specific character sequence (\r\n for example).

Ref : https://bit.ly/3hcyege

 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook