Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End explanation of PHP code

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #179393
    Anonymous
    Inactive

    I have a good idea of whats going on here but there sections of the following PHP code that i don’t fully understand so it would be great if someone could explain them to me in a direct manner so that its easier to understand.

    `
    try {

        $user = "root";
        $pass = "Jv9524500";
        $db = "Practice";
    
        $connect = new PDO("mysql:host=localhost; dbname=$db", $user, $pass);
    
        $connect -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    } catch( PDOException $e ) {
    
        $e -> getMessage();
        echo "Couldn't connect to the database";
        die();
    
    }
    

    `

    1. What exactly does the arrow mean in $connect -> setAttribute
    2. Whats going on in this line? } catch( PDOException $e ) {
    3. What exactly is PDO and new PDO?
    #179397
    __
    Participant
    1. The -> arrow is used to call a method on an object; in this case, the setAttribute method on your PDO object.
    2. You use try … catch blocks for exception-based error handling. In basic terms, if there is an exception thrown in your try block, you skip directly to the catch block and do something about it (although, die is not the best solution).
    3. PDO is a php extension used for connecting to various SQL databases, such as MySQL.
    #179398
    __
    Participant

    @TheDoc / @Paulie_D, I lost a comment here, if you could kindly restore it … :)

    #179410
    Anonymous
    Inactive

    Yea that seems to be a huge issue. Posts don’t actually show up.

    #179438
    Senff
    Participant

    @traq — comment restored (was likely automatically moved to spam folder because it contained more than 3 links).

    #179496
    __
    Participant

    thanks @Senff

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.