$dbh = new PDO("mysql:host
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>$host = "localhost";//Ip of database, in this case my host machine
$user = "root"; //Username to use
$pass = "qwerty";//Password for that user
$dbname = "DB";//Name of the database
try {
$connection = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e)
{
echo $e->getMessage();
}
Also in PHP:
- check variable type in php
- change to uppercase php
- check laravel version
- download php7.4 aptget
- composer get version from php
- dateFormat php
- check email exist or not wordpress
- determine type in function php
- clean redis cache
- error_reporting function not working
- Impossible de trouver le paquet php-gettext
- App\Http\Controllers\Validator not found
- do_shortcode not working
- check index of string php
- errno: 150 foreign key constraint is incorrectly formed laravel 8
- create project larave
- array_key_exists php to python
- carbon add minutes
- easy admin bunfle symfony modify login page
- change timestamp to date php
- cannot use font awesome in php mvc
- acf field without spaces
- copy php array to another
- /phpspreadsheet 1.15.0 requires ext-dom * centos yum