no more mysql_query in the whole thing
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Thu, 30 Dec 2004 09:12:06 +0000 (09:12 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:05 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-192

htdocs/banana/include/profile.inc.php
htdocs/banana/include/session.inc.php
htdocs/banana/include/subscribe.inc.php

index 034d870..95212ff 100644 (file)
@@ -27,11 +27,12 @@ function getprofile() {
         global $globals;
         
         $uid = Session::getInt('uid');
-       $req = mysql_query("SELECT  nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'),
-                                   IF(FIND_IN_SET('automaj',flags),'1','0') 
-                             FROM  {$globals->banana->table_prefix}profils
-                            WHERE  uid=$uid");
-       if (!(list($nom,$mail,$sig,$disp,$maj)=mysql_fetch_row($req))) {
+       $req = $globals->xdb->query(
+                "SELECT  nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'),
+                         IF(FIND_IN_SET('automaj',flags),'1','0') 
+                   FROM  {$globals->banana->table_prefix}profils
+                  WHERE  uid={?}", $uid);
+       if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
            $nom  = Session::get('prenom')." ".Session::get('nom');
            $mail = Session::get('forlife')."@polytechnique.org";
            $sig  = $nom." (".Session::getInt('promo').")";
@@ -47,17 +48,14 @@ function getprofile() {
        $array['lastnews']  = Session::get('banana_last');
        $array['dropsig']   = true;
        if ($maj) {
-           mysql_query("UPDATE auth_user_quick SET banana_last='"
-               .gmdate("YmdHis")."' WHERE user_id=$uid");
-       }
-       $req=mysql_query("SELECT  nom
-                           FROM  {$globals->banana->table_prefix}abos
-                      LEFT JOIN  {$globals->banana->table_prefix}list ON list.fid=abos.fid
-                          WHERE  uid=$uid");
-       $array['subscribe']=array();
-       while (list($fnom)=mysql_fetch_array($req)) {
-           array_push($array['subscribe'],$fnom);
+            $globals->xdb->execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", gmdate("YmdHis"), $uid);
        }
+       $req = $globals->xdb->query(
+                "SELECT  nom
+                   FROM  {$globals->banana->table_prefix}abos
+              LEFT JOIN  {$globals->banana->table_prefix}list ON list.fid=abos.fid
+                  WHERE  uid={?}", $uid);
+       $array['subscribe'] = $req->fetchColumn();
     } else {
        $array = array();
     }
index 492d10e..f2148fe 100644 (file)
@@ -1,31 +1,31 @@
 <?php
 /********************************************************************************
-* include/session.inc.php : sessions for profile
-* -------------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
+ * include/session.inc.php : sessions for profile
+ * -------------------------
+ *
+ * This file is part of the banana distribution
+ * Copyright: See COPYING files that comes with this distribution
+ ********************************************************************************/
 
 $sname = $_SERVER['SCRIPT_NAME'];
 $array = explode('/',$sname);
 $sname = array_pop($array);
 unset($array);
 switch ($sname) {
-    case "thread.php":
+    case 'thread.php':
         if (!Session::has('bananapostok')) {
-            $_SESSION['bananapostok']=true;
+            $_SESSION['bananapostok'] = true;
         }
-    break;
-    
-    case "index.php":
+        break;
+
+    case 'index.php':
         if (Get::get('banana') == 'updateall') {
-            mysql_query("UPDATE auth_user_quick SET banana_last='"
-                    .gmdate("YmdHis")."' WHERE user_id=".Session::getInt('uid'));
-            $_SESSION["banana_last"]=time();
+            $globals->xdb->execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', gmdate('YmdHis'), Session::getInt('uid'));
+            $_SESSION['banana_last'] = time();
         }
 
     default:
-    $_SESSION['bananapostok']=true;
+        $_SESSION['bananapostok'] = true;
 }
+
 ?>
index 1a66fc9..6e86c65 100644 (file)
@@ -8,16 +8,18 @@ function update_subscriptions($_subscriptions) {
     global $globals;
     $uid = Session::getInt('uid');
 
-    mysql_query("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid='$uid'");
+    $globals->xdb->execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
     if (!count($_subscriptions)) {
         return true;
     }
+    
     // Récupération des fid
-    $req = mysql_query("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
-    $fids=array();
-    while (list($fid,$fnom)=mysql_fetch_row($req)) {
-        $fids[$fnom]=$fid;
+    $req  = $globals->xdb->iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
+    $fids =array();
+    while (list($fid,$fnom) = $req->next()) {
+        $fids[$fnom] = $fid;
     }
+
     // MAJ table de forums
     if (count(array_keys($fids))) {
         $diff = array_diff($_subscriptions,array_keys($fids));
@@ -26,13 +28,13 @@ function update_subscriptions($_subscriptions) {
     }
     if (count($diff)) {
         foreach ($diff as $g) {
-            mysql_query("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ('$g')");
-            $fids[$g]=mysql_insert_id();
+            $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
+            $fids[$g] = mysql_insert_id();
         }
     }
     // MAJ Abonnements
     foreach ($_subscriptions as $g) {
-        mysql_query("REPLACE INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ('{$fids[$g]}','$uid')");
+        $globals->xdb->execute("REPLACE INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", $fids[$g], $uid);
     }
 }