Current location: Hot Scripts Forums » Programming Languages » PHP » safe pdo insert and update


safe pdo insert and update

Reply
  #1 (permalink)  
Old 10-31-08, 06:18 PM
ushtabalakh ushtabalakh is offline
New Member
 
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
safe pdo insert and update

I'm trying to make a function that I can use safely every time I wanna insert or update anything using PDO

Here is what I have made
PHP Code:



    $dbName 
"mydb";
    
$dbServerAddress "localhost";
    
$dbUsername "root";
    
$dbPassword "somepassword";
    
$dsn "mysql:dbname="$dbName .";'"$dbServerAddress ."'";
global 
$db;
$db = new PDO($dsn,$dbUsername,$dbPassword);
        

function 
ExecuteQuery2($query,$arrayOfValues){
    
    global 
$db;
    
$sth $db->prepare($query);
    
$sth->execute($arrayOfValues); 
    print 
$sth-> errorCode();
    print 
$sth-> errorInfo();


And here is how I'm trying to use it
PHP Code:

  $username "blabla";

     
$email "blabla@yahoo.com";
     
$password "blabla";
     
$homepage "http://www.blabla.com";
     
    
ExecuteQuery2("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 )); 
I receive this error when running the codE:
23000Array

What seems to be the issue?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert and update in the same time Full Moon Database 7 05-30-07 02:51 AM
Update multiple rows outside loop - need help ElvansX PHP 1 12-03-06 01:55 AM
MySQL, UPDATE vs DELETE and INSERT nassau PHP 6 01-16-06 12:59 PM
MySQL insert record if update fails? perleo PHP 3 01-06-06 02:21 PM
SQL Update TizMe PHP 0 09-19-05 03:29 AM


All times are GMT -5. The time now is 08:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.