www.webdeveloper.com
Results 1 to 8 of 8

Thread: PDO prepared statement

Threaded View

  1. #1
    Join Date
    Nov 2009
    Posts
    97

    PDO prepared statement

    Hello everyone,

    I am trying to use PDO for my new projects and I can't seem to understand or at least find a good example on prepared statements, I have an update query that works fine but I know I'm not using it right for the data sanitation feature that PDO offers, this is my code:

    PHP Code:
    $data $conn->query("SELECT * FROM adminUsers INNER JOIN permissions ON adminUsers.adminUserID=permissions.adminUserID");
    while (
    $row $data->fetch(PDO::FETCH_ASSOC)){
        
    $sql "UPDATE adminUsers, permissions SET 
            adminUsers.name = '"
    .$_POST['name']."', 
            adminUsers.lastName = '"
    .$_POST['lastName']."', 
            adminUsers.email = '"
    .$_POST['email']."', 
            permissions.superAdmin = '"
    .$_POST['superAdmin']."' , 
            permissions.editAdminUsers = '"
    .$_POST['editAdminUsers']."' , 
            permissions.deleteAdminUsers = '"
    .$_POST['deleteAdminUsers']."' , 
            permissions.editUsers = '"
    .$_POST['editUsers']."' , 
            permissions.deleteUsers = '"
    .$_POST['deleteUsers']."' 
        WHERE adminUsers.adminUserID = '"
    .$_POST['id']."' && permissions.adminUserID = '".$_POST['id']."'";
        
    $sql $conn->prepare($sql);
        
    $sql->execute(array(':name'=>$row['name'],
                            
    ':lastName'=>$row['lastName'],
                            
    ':email'=>$row['email'],
                            
    ':superAdmin'=>$row['superAdmin'],
                            
    ':editAdminUsers'=>$row['editAdminUsers'],
                            
    ':deleteAdminUsers'=>$row['deleteAdminUsers'],
                            
    ':editUsers'=>$row['editUsers'],
                            
    ':deleteUsers'=>$row['deleteUsers']));


    Could someone please tell me what is the right way to use PDO in this case?

    Thanks a lot for any help provided.
    Last edited by NogDog; 02-01-2013 at 10:37 PM. Reason: changed [code] tags to [php] tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles