PHP mysqli: connect_errno() function
mysqli_connect_errno() function / mysqli::$connect_errno
The mysqli_connect_errno() function / mysqli::$connect_errno returns the error code from the last connection error, if any.
Syntax:
Object oriented style
int $mysqli->connect_errno;
Procedural style
int mysqli_connect_errno ( void )
Usage: Procedural style
mysqli_commit(connection);
Return value:
An error code value for the last call to mysqli_connect(), if it failed. zero means no error occurred.
Version: PHP 5, PHP 7
Example of object oriented style:
<?php
$mysqli = @new mysqli('localhost', 'user1', 'datasoft123', 'hr');
if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}
?>
Example of procedural style:
<?php
$link = @mysqli_connect('localhost', 'user1', 'datasoft123', 'hr');
if (!$link) {
die('Connect Error: ' . mysqli_connect_errno());
}
?>
Output:
Connect Error: 1045
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
Previous: commit
Next: connect_error
PHP: Tips of the Day
PHP: Saving image from PHP URL
If you have allow_url_fopen set to true:
$url = 'http://example.com/image.php'; $img = '/my/folder/flower.gif'; file_put_contents($img, file_get_contents($url));
Else use cURL:
$ch = curl_init('http://example.com/image.php'); $fp = fopen('/my/folder/flower.gif', 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp);
Ref : https://bit.ly/2Q93gK6
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
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