How to properly set up a PDO connection

后端 未结 4 1558
温柔的废话
温柔的废话 2020-11-21 07:24

From time to time I see questions regarding connecting to database.
Most answers is not the way I do it, or I might just not get the answers correctly. Anyway; I\'ve nev

4条回答
  •  感动是毒
    2020-11-21 08:09

    $dsn = 'mysql:host=your_host_name;dbname=your_db_name_here'; // define host name and database name
        $username = 'you'; // define the username
        $pwd='your_password'; // password
        try {
            $db = new PDO($dsn, $username, $pwd);
        }
        catch (PDOException $e) {
            $error_message = $e->getMessage();
            echo "this is displayed because an error was found";
            exit();
    }
    

提交回复
热议问题