Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/12/2014, 11:16
rahe_meph
 
Fecha de Ingreso: marzo-2013
Mensajes: 26
Antigüedad: 11 años, 2 meses
Puntos: 0
Respuesta: Conexiones a la bd y servidor

Gracias por responder, son consultas muy basicas,este es el script a ejecutar por 100 personas en un tiempo muy corto, (menos de un minuto).
Código PHP:
Ver original
  1. <?php
  2. require("../conexion.php");
  3.  
  4. $user=$_SESSION["id_user"];
  5. $id=$_POST["id"];
  6. $fecha_i=$_POST["start"];
  7. $fecha_f=$_POST["end"];
  8. $interv1=$_POST["interv1"];
  9. $interv2=$_POST["interv2"];
  10.  
  11. function minutos_transcurridos($fecha_i,$fecha_f){
  12.     $minutos = (strtotime($fecha_i)-strtotime($fecha_f))/60;
  13.     $minutos = abs($minutos); $minutos = floor($minutos);
  14.     return $minutos;
  15. }
  16.  
  17. $sql1="select id_usuario,start,end from turnos_toma
  18. where start='".$fecha_i."' and end='".$fecha_f."' and id_usuario=".$user." limit 1";
  19. $res1=mysqli_query($conexion,$sql1);
  20. $num1=mysqli_num_rows($res1);
  21.     if ($num1!="0") {
  22.         echo "Ya tomaste este turno!";exit;
  23.     }else{
  24.  
  25.     $sql2="SELECT count(id) as cantidad from turnos_toma
  26.     where start BETWEEN '".$interv1."'  AND '".$interv2."' and id_usuario=".$user."";                                  
  27.     $res2=mysqli_query($conexion,$sql2);
  28.     $count2 = mysqli_fetch_array($res2);
  29.         if ($count2[0]==4) {
  30.             echo "No puedes tomar más de 4 turnos.";exit;
  31.         }else{             
  32.  
  33.             $sql3="select start from turnos_toma where
  34.             start BETWEEN '".$interv1."'  AND '".$interv2."' and
  35.             id_usuario=".$_SESSION["id_user"]."";
  36.             $res3=mysqli_query($conexion,$sql3);
  37.             $num3 = mysqli_num_rows($res3);
  38.                 if ($num3==0) {
  39.                     $sql4="update turnos_asignacion set cantidad=cantidad-1 where id=".$id."";
  40.                     $res4=mysqli_query($conexion,$sql4);
  41.                     $sql5="insert into turnos_toma values(null,".$id.",".$user.",'".$fecha_i."','".$fecha_f."')";
  42.                     $res5=mysqli_query($conexion,$sql5);
  43.                     echo "Turno tomado con éxito";exit;
  44.                 }else{
  45.  
  46.                     while ($row3=mysqli_fetch_array($res3)) {  
  47.                         if (minutos_transcurridos($row3["start"],$fecha_i)<210) {
  48.                             echo "No puedes tomar este turno.";exit;
  49.                         }
  50.                     }      
  51.                    
  52.                     $sql6="update turnos_asignacion set cantidad=cantidad-1 where id=".$id."";
  53.                     $res6=mysqli_query($conexion,$sql6);
  54.                     $sql7="insert into turnos_toma values(null,".$id.",".$user.",'".$fecha_i."','".$fecha_f."')";
  55.                     $res7=mysqli_query($conexion,$sql7);
  56.                     echo "Turno tomado con éxito";exit;
  57.                 }
  58.            }
  59.     }
  60.  
  61. mysqli_close($conexion);
  62.  
  63. ?>

asi que creo que tendre que probar algun hosting, alguna recomendación?