Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //This script, in some cases, may cause issues with the options. If things are not working as expected then comment out the 2nd option,
- // \PDO::ATTR_DEFAULT_FETCH_MODE and try testing your project again.
- $DB_HOST = 'localhost';
- $DB_LOGIN = 'root';
- $DB_PASS = 'password';
- $DB_NAME = 'Your_Database_Name';
- $charset = 'utf8mb4';
- $options = [
- \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
- \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
- \PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $dsn = "";
- try{
- $dsn = "mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$charset";
- $pdo = new PDO($dsn, $DB_LOGIN,$DB_PASS,$options);
- $connected = "<hr><p>Connected to the ".$DB_NAME." database</p>";
- echo $connected; //Echo this var, and the line above, out of your code when in production. This is only to test connection
- }catch(PDOException $e){
- die ('Connection Failed: '.$e->getMessage());
- }
Advertisement
Add Comment
Please, Sign In to add comment