Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

Connecting to a MySQL database with PDO

David Carr

PHP & MySQL Tutorials

  • The Source Code
  • This video covers connection to a database using PDO in a try catch block with Exceptions.

    The Source Code

    <?php
    
    try {
    
        $db = new PDO('mysql:host=localhost;dbname=temp','root','root');
        
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    ?>

     

    Laravel Modules Book by David Carr

    Help support the blog so that I can continue creating new content!

    Subscribe to my newsletter

    Subscribe and get my books and product announcements.

    © 2009 - 2022 DC Blog. All code MIT license. All rights reserved.