Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2012, 12:50 AM   PM User | #1
Gamerholic
New Coder

 
Join Date: Mar 2012
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Gamerholic is an unknown quantity at this point
Insert/Update

Can someone please help me interpret this format as an insert and update statement. I'm use to writing php the old way.

//insert gameid,player_id,starttime,submitted values :gameid, //layer_id,now(),'N'

//insert statement will send the insert id back as json

Update statement will get the update as ending_score_id and update that table id.

PHP Code:
        $db = new PDO('mysql:host=localhost;dbname=xxxx''xxxx''xxxxx');
        
$db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_WARNING);

//insert gameid,player_id,starttime,submitted values :gameid, //:player_id,now(),'N'

//insert statement will send the insert id back as json

        
$st $db->prepare("SELECT * FROM `ttourmember` WHERE `player_token` = :player_token AND `isactive`='Y'"); // need to filter for next auction
        
$st->bindParam(':player_token'$_GET['player_token']); // filter

        
$st->execute();
        
$r $st->fetch(PDO::FETCH_ASSOC);
        
               if(empty(
$_GET['token']) || $_GET['token'] == '0000' || $st->rowCount() == ): // Return Error if Token Doesn't exist or no db result
            
$return = array('DBA_id'=>'0000');
            echo 
json_encode($return);
        else:
           
            
$return = array(
                
'DBA_pending_score_id'=>$r['insert_id'],
                );
            echo 
json_encode($return); 
Gamerholic is offline   Reply With Quote
Old 11-15-2012, 02:54 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Inserts and Updates are more simple than Selects, because you don't have to fetch anything. Just call the prepare method:

http://us3.php.net/manual/en/pdo.prepare.php

Be sure to bind the parameters (values) that you will be inserting or updating:

http://us3.php.net/manual/en/pdostatement.bindparam.php

And then call the execute method:

http://us3.php.net/manual/en/pdostatement.execute.php

And finally you can grab the inserted ID using the lastinsertid method:

http://us3.php.net/manual/en/pdo.lastinsertid.php
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:01 AM.


Advertisement
Log in to turn off these ads.