Forums

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

Home Forums Back End Extending PDO Class

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32551
    ChrisBull
    Member

    I am running a site that is using a design pattern (can’t remember what its called but its the one where you have a registry file that is on all pages and can store objects). Anyway, I need to create an object for database operations and would like to use PDO.

    So i need to create a class that extends the pdo class.

    Can someone either point me in the direction of a tutorial, a class someone has already made or outline the structure so i can make my own? I can’t currently find a completed one online or a tutorial to make one.

    many Thanks
    Chris

    #46876
    cmegown
    Member

    This is always a rock-solid reference:
    PHP Manual – PDO

    It’ll show you how to make a PDO connection:
    $conn = new PDO(‘mysql=localhost;dbname=db’, $username, $password);

    And how to make prepared/bound queries, to prevent SQL injections:
    $query = “select count(*) from table where email = ?”;
    $stmt = $conn->prepare($query);
    $stmt->bindParam(1, $variable, PDO::PARAM_STR);
    $stmt->execute();
    $result = $stmt->fetchAll();

    Hope that helps a wee bit.

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