SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: CRUD

  1. #1
    SitePoint Addict
    Join Date
    Dec 2011
    Posts
    221
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    CRUD

    Hello! Been looking for the solution for a week. I'm new in oop and pdo. In my update form, I just want to show in the textbox the value ready, every time I edit a data.

    I'm using this tuts http://phpeasy.co.uk/tutorial-object...-crud-methods/

    Help me out of this please. tnx.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    What exactly is the problem?

  3. #3
    SitePoint Addict
    Join Date
    Dec 2011
    Posts
    221
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    My problem is how to make function that will show value from my db. I made this thing and I'm not sure about it.
    public function viewItem(){
    self::conn();
    try{
    $sql = "SELECT * FROM dbo.guitar WHERE id=:id";

    $q = self::$db->prepare($sql);
    $q->execute();
    $row = $q->rowCount();

    $results = $q->fetchAll(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE,
    "Guitar",
    array('id', 'make', 'model', 'colour', 'price'));
    s
    }
    catch (Exception $e){
    print "Error!: " . $e->getMessage();
    }

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Well for starters, your execute doesnt declare what the value of :id should be...
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    From your post it seems you are teaching yourself OOP and PDO simultaneously, but it seems to me you have not grasped the PDO basics.

    I really don't think this is a good strategy, there is just far too much that can go wrong and for anyone here to provide any meaningful assistance -- you will end up posting reams of code which will itself put others off helping you.

    Please don't take this the wrong way, but I am sure it would help if you just back up a little bit and take on PDO on its own (which already a handful).

    I know that PDO is an OOP class, but using an object is far easier to learn than creating classes.

    Assuming your SQL skills are good, what you need to do is spend a day or so looking at PDOs documentation and working through some examples using PDO as userland code rather than trying to encapsulate it in other Classes. (ie you set up your connection, and call a new PDO(), then iterate through some results sets, arrays, objects, single rows and so on as PHP code).

    PDO tutorials

    Wez Furlongs original PHP Data Objects slides were my kicking off point, and might provide a useful birds eye view.

    Once you have established for yourself some working examples of each of the options available to PDO, and have understood its relationship to the entirely different PDOStatement class, you will be ready to roll with that CRUD tutorial.

    Good luck with it, and if you have questions, then do come back and ask.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •