$db = new PDO
<?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:
- duplicate array values php
- currunt date time in php
- PHP Fatal error: Composer detected issues in your platform: Your Composer depen dencies require a PHP version ">= 7.3.0". You are running 7.2.34.
- Error: Cannot redeclare composerRequire1d8e02dff94f518b7a14ddcb6710f10d() (previously declared in /Applications/XAMPP/xamppfiles/htdocs/all4learn2/Vendor/composer/autoload_real.php:66)
- !is_null in laravel
- check if date is within range php
- count charcter in php
- codeigniter sms send
- Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 9263312 bytes) in /home/arsalan farooq/local security.uk/wp-includes/wp-db.php
- encryption and decryption in php example
- date remove 7 days php
- date format with t and z php
- Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) laravel
- consloe.log php
- Tto upper php
- check network connection php
- __PHP_Incomplete_Class
- check if char exists in string php
- apt-get install php 7.4
- create new project in laravel 7
- count characters laravel
- Allowed memory size of 536870912 bytes exhausted (tried to allocate 264245248 bytes) http://localhost:8000/createProduct
- find string php
- dmY PHP