Advertisement
Kagee

Untitled

May 23rd, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. /*
  3.  * , du tar tiden ved å kjøre microtime() før og etter og måler forskjellen
  4. 16:31 <@echofish> så kjedelig du er
  5. 16:31 <@AlecTBM> altså $newtime-$oldtime
  6.  
  7.  *
  8.  * */
  9. try {
  10.     $debug = "true";
  11.     require_once('db.php');
  12.     $dbh = new PDO($dbd, $dbu, $dbp);
  13.    
  14.     $dbh->beginTransaction();
  15.    
  16.     $stmt = $dbh->prepare("SELECT * FROM `looking` LIMIT 2");
  17.     $stmt->bindParam(':s', $session, PDO::PARAM_STR);
  18.     dump("stmex-execute-select-players",$stmt->execute());
  19.  
  20.     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  21.     dump("result-select-players",$result);
  22.     if(count($result) == 2) {
  23.         dump("result-two",$result);
  24.         echo "count 2";
  25.  
  26.         $sql = "INSERT INTO  `rag`.`players` (`sess` ,`targetIP` ,`targetPORT`, `accepted`) ";
  27.         $sql .="VALUES (:s,  :i,  :p, 0)";
  28.         $stmt = $dbh->prepare($sql);
  29.         $stmt->bindParam(':s', $result[0]['sess'], PDO::PARAM_STR);
  30.         $stmt->bindParam(':i', $result[1]['IP'], PDO::PARAM_STR);
  31.         $stmt->bindParam(':p', $result[1]['PORT'], PDO::PARAM_STR);
  32.         dump("stmex-execute-insert-player-0",$stmt->execute());
  33.  
  34.         $stmt = $dbh->prepare($sql);
  35.         $stmt->bindParam(':s', $result[1]['sess'], PDO::PARAM_STR);
  36.         $stmt->bindParam(':i', $result[0]['IP'], PDO::PARAM_STR);
  37.         $stmt->bindParam(':p', $result[0]['PORT'], PDO::PARAM_STR);
  38.         dump("stmex-execute-insert-player-1",$stmt->execute());
  39.        
  40.         $sql = "DELETE FROM `rag`.`looking` WHERE `looking`.`sess` = :sone OR `looking`.`sess` = :stwo LIMIT 2";
  41.         $stmt = $dbh->prepare($sql);
  42.         $stmt->bindParam(':sone', $result[0]['sess'], PDO::PARAM_STR);
  43.         $stmt->bindParam(':stwo', $result[1]['sess'], PDO::PARAM_STR);
  44.         dump("stmex-execute-delete-player-0-and-1",$stmt->execute());
  45.        
  46.     } else {
  47.         dump("result-not",$result);
  48.         echo "count !2";
  49.     }
  50.     $dbh->commit();
  51. } catch (PDOException $e)
  52. {
  53.     $dbh->rollBack();
  54.     fail_and_die('exception: '.$e->getMessage());
  55. }
  56.  
  57. function dump($msg, $var) {
  58.     global $debug;
  59.     if($debug == "true") {
  60.         echo "<br><br>$msg<pre>";
  61.         var_dump($var);
  62.         echo "</pre>";
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement