Database connection + queries class

Discussion in 'PHP' started by Chetan Tudor, Dec 27, 2015.

  1. #1
    Hello, I want to build a class that handles the database connection and the queries. When I have a select query( select name, surname from users where 1 ) for example, I bind the results to let's say $bind1 and $bind2 and while the statement fetches I print the result. My question is how should I return the results outside the class, because there could be more than two binded variables. Probaby the design I'm thinking of isn't very good and should be started from zero.
     
    Chetan Tudor, Dec 27, 2015 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,875
    Likes Received:
    4,547
    Best Answers:
    123
    Trophy Points:
    665
    #2
    I'd start with a review of other database connection libraries. Don't copy what they do but try to understand why they make the decisions they make and understand how that both limits them and enhances them. Once you have done that 3 or 4 times you'll have a better idea of how yours should look.

    As an example... many cater for database queries that I'll never need to use, so if I were to write a library I can simplify things and reduce the bloat.
     
    sarahk, Dec 27, 2015 IP
  3. Chetan Tudor

    Chetan Tudor Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #3
    Could you give me one or two links ? I have been studying two libraries but they didn't use parameterized queries and had some vulnerabilities
     
    Chetan Tudor, Dec 27, 2015 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,875
    Likes Received:
    4,547
    Best Answers:
    123
    Trophy Points:
    665
    #4
    If you can't find any good libraries start with joomla, wordpress and any of the frameworks. They have database libraries built in.

    In wordpress look for /includes/wp-db.php
     
    sarahk, Dec 27, 2015 IP
  5. Chetan Tudor

    Chetan Tudor Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #5
    Thanks, I will study it in the morning
     
    Chetan Tudor, Dec 27, 2015 IP