Connections are established by creating instances of the PDO base class
<?php
try {
$dsn='mysql:host=localhost;dbname=test';
$username='root';
$password='root';
$con= new PDO($dsn, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
NOTE : - If there are any connection errors, a PDOException object will be thrown.You may catch the exception if you want to handle the error condition.
<?php
try {
$dsn='mysql:host=localhost;dbname=test';
$username='root';
$password='root';
$con= new PDO($dsn, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
NOTE : - If there are any connection errors, a PDOException object will be thrown.You may catch the exception if you want to handle the error condition.
How to get ip address in php?
ReplyDelete$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.
Delete'REMOTE_ADDR'
The IP address from which the user is viewing the current page.