Safe way to execute insert and update using PDO

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ushtabalakh
Forum Newbie
Posts: 4
Joined: Fri Oct 24, 2008 2:59 am

Safe way to execute insert and update using PDO

Post by ushtabalakh »

I'm trying to write a function that I can use later to make safe insert and update calls using PDO's prepare functionality
This is what I have came up with so far

Code: Select all

function ExecuteQuery($query,$arrayOfValues){
    global $db;
    $del = $db->prepare($query);
    $del->execute($arrayOfValues);
    $count = $del->rowCount();  
    return $count;
}
I wish to use this function like this:

Code: Select all

 
$count = ExecuteQuery("insert into users (`verified`,`username`,`email`,`password`,`avatarid`,`homepage`,`lastlogin`,`sentitems`,`passworddate`,`title`,`allowedtosend`,`changePassKey`) values  (1, '?','?','?',0,'?',CURDATE(),0,CURDATE(),'',0,0",array( $username , $email , $password , $homepage ));
 
But it doesn't work, I receive 0 every time I run the function
What seems to be the problem?
ushtabalakh
Forum Newbie
Posts: 4
Joined: Fri Oct 24, 2008 2:59 am

Re: Safe way to execute insert and update using PDO

Post by ushtabalakh »

How do you guys perform a safe sql insert or update then? :crazy:
Post Reply