Erreur mysql_affected_row()?

Signaler
Messages postés
294
Date d'inscription
jeudi 8 février 2007
Statut
Membre
Dernière intervention
3 décembre 2012
-
Messages postés
2483
Date d'inscription
jeudi 30 novembre 2006
Statut
Membre
Dernière intervention
14 janvier 2011
-
salut,

Je réalise un analyseur de log en php!!! j'ai trouvé sur le net un qui le fait en interéagissant avec Postgresql mais puisque il voulez pa s'installer sur ma machine...!!! mais sa me sort les erreur suivante lorsque je lance le script de parsing, le voila:


<?


ini_set ("max_execution_time", "21600");
require ("config.inc");


//////
$con=mysql_connect("127.0.0.1",$db_user,$db_pass);
$conex=mysql_select_db($db_name,$con);
//$con_string = "host=$db_host port=5432 dbname=$db_name user=$db_user password=$db_pass";
//$conex = pg_connect ($con_string);


$log = fopen ($log_file, "r");


if ($log <> "") {
   $err = 0;
   $pasadas = 0;
   if (!feof($log)) {
      $linea = fgets($log);
      $arr = explode(' ', $linea);
      list ($hora, $mili) = explode ('.', $arr[0]);
      $tiempo = date("m/d/y H:i:s", $hora).".$mili";
     
   ///////////   $res mysql_query ("SELECT time FROM log WHERE time '$tiempo';") or die(mysql_error());   //$res pg_query ($conex, "SELECT time FROM log WHERE time '$tiempo'");
      if (mysql_num_rows($res))
      {
         $continua = 0;
         echo "No se puede procesar este archivo, ya existe un registro en la B.D con el mismo tiempo que el primer registro del archivo, posiblemente se deba a que este ya fue procesado";
         $start = time();
      }
      else
      {
         $continua = 1;
         $start = time();
      }
   }


   $i = 0;
   while (!feof($log) && $continua == 1) {
      $j = 0;
      foreach ($arr as $str)
         if ($str <> '') {
            $registro[$j] = $str;
            $j++;
         }
      list ($tiempo, $transcurrido, $equipo_remoto, $codigo_status, $bytes, $metodo, $url, $autenticacion, $peerstatus_peerhost, $tipo) = $registro;
      if (strpos($url, '//') != false)
         list ($proto, $aux, $dir, $dir_arg) = explode ('/', $url, 4);
      else
         list ($dir, $dir_arg) = explode ('/', $url, 4);
      $dir_arg = addslashes ($dir_arg);
      $dir_arg = substr ($dir_arg, 0, 1023);
      list ($codigo, $status) = explode ('/', $codigo_status);
      list ($peerstatus, $peerhost) = explode ('/', $peerstatus_peerhost);
      list ($hora, $mili) = explode ('.', $tiempo);
      $tiempo = date("m/d/y H:i:s", $hora).".$mili";
      list ($tipo1, $tipo2) = explode ('/', $tipo);


      $res = mysql_query ("INSERT INTO log (time,elapsed,remote_host,code,status,bytes,method,protocolo,direccion,argumento_url,username,peerstatus,peerhost,type1,type2) VALUES('$tiempo',$transcurrido,'$equipo_remoto','$codigo','$status',$bytes,'$metodo','$proto','$dir','$dir_arg','$autenticacion','$peerstatus','$peerhost','$tipo1','$tipo2');") or die(mysql_error());
   //$res = pg_query ($conex, "INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('$tiempo', $transcurrido, '$equipo_remoto', '$codigo', '$status', $bytes, '$metodo', '$proto', '$dir', '$dir_arg', '$autenticacion', '$peerstatus', '$peerhost', '$tipo1', '$tipo2')");
     
   if (mysql_affected_rows($res))        ////////////??????????
   //if (pg_affected_rows($res))
     
      $pasadas++;
      else {
         $err++;
         echo "
Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('$tiempo', $transcurrido, '$equipo_remoto', '$codigo', '$status', $bytes, '$metodo', '$proto', '$dir', '$dir_arg', '$autenticacion', '$peerstatus', '$peerhost', '$tipo1', '$tipo2')";
      }


      $linea = fgets($log);
      $arr = explode(' ', $linea);
      $j = 0;
      foreach ($arr as $str)
         if ($str <> '') {
            $registro[$j] = $str;
            $j++;
         }
   }


   ///////////////
   mysql_query ("VACUUM ANALYZE");
   //pg_query ("VACUUM ANALYZE");
   mysql_close ();
   //pg_close ($conex);
  
   fclose($log);
   $end = time();
   $duracion = ($end - $start) / 60.0;
   $start = date("m/d/y H:i:s", $start);
   $end = date("m/d/y H:i:s", $end);
   $prom = ($err * 100.0)/($pasadas + $err);
   echo "
Procesadas: $pasadas
Errores: $err
Promedio Errores: $prom%";
   echo "
Inicio: $start - Finalización: $end - Duración: $duracion Minutos";
}
?>

Ca me sort les erreur suivantes:

...................


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:21.387', 2491, '172.31.13.178', 'TCP_MISS', '200', 1189, 'GET', 'http:', 'ie.fr.msn.com', 'ie5/search/pub.asp', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:21.622', 4, '172.31.13.178', 'TCP_IMS_HIT', '304', 205, 'GET', 'http:', 'ads.eu.msn.com', 'ads/FRMIEG/HL080009_SM.GIF', '-', 'NONE', '-', 'image', 'gif ')
Notice: Undefined offset: 1 in c:\users\el_diablo\desktop\squid_log\parse.php on line 78


Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:21.810', 330, '172.31.13.178', 'TCP_MISS', '000', 561, 'GET', 'http:', 'ie.fr.msn.com', 'images/fond3.gif', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', '- ', '')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:22.649', 1809, '172.31.13.178', 'TCP_MISS', '200', 1194, 'GET', 'http:', 'ie.fr.msn.com', 'ie5/search/pub.asp', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:22.720', 70, '172.31.13.178', 'TCP_NEGATIVE_HIT', '404', 712, 'GET', 'http:', 'ie.fr.msn.com', 'images/fond3.gif', '-', 'NONE', '-', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:22.803', 3, '172.31.13.178', 'TCP_IMS_HIT', '304', 205, 'GET', 'http:', 'ads.eu.msn.com', 'ads/FRMIEG/HL080006_SM.GIF', '-', 'NONE', '-', 'image', 'gif ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:27.394', 3, '172.31.13.178', 'TCP_IMS_HIT', '304', 205, 'GET', 'http:', 'ie.search.msn.com', 'fr/srchasst/srchasst.htm', '-', 'NONE', '-', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:28.432', 3, '172.31.13.178', 'TCP_IMS_HIT', '304', 205, 'GET', 'http:', 'ie.search.msn.com', 'fr/srchasst/srchasst.htm', '-', 'NONE', '-', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:32.409', 1185, '172.31.13.166', 'TCP_MISS', '200', 2659, 'GET', 'http:', 'www.umedia.univ-nantes.fr', 'MSM/index.htm', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', 'text', 'html ')
Notice: Undefined offset: 1 in c:\users\el_diablo\desktop\squid_log\parse.php on line 78


Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:34.130', 1460, '172.31.13.166', 'TCP_MISS', '000', 0, 'GET', 'http:', 'www.compteur.com', 'cgi-bin/compteur.cpt?', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', '- ', '')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:35.810', 1156, '172.31.13.166', 'TCP_MISS', '200', 1595, 'GET', 'http:', 'www.umedia.univ-nantes.fr', 'MSM/PAGES/APS.htm', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:36.767', 957, '172.31.13.166', 'TCP_MISS', '200', 2437, 'GET', 'http:', 'www.umedia.univ-nantes.fr', 'MSM/PAGES/images/assoaps.gif', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', 'image', 'gif ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:38.309', 911, '172.31.10.3', 'TCP_MISS', '302', 393, 'GET', 'http:', 'www2.certi.adc.education.fr', 'ami/delvoeu.htm?', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Error insertando: INSERT INTO log (time, elapsed, remote_host,code, status, bytes, method, protocolo, direccion, argumento_url, username, peerstatus, peerhost, type1, type2) VALUES ('02/24/00 15:40:40.215', 1906, '172.31.10.3', 'TCP_MISS', '200', 4726, 'GET', 'http:', 'www2.certi.adc.education.fr', 'ami/lvoeux.htm?', '-', 'DEFAULT_PARENT', 'sat-epinal.ac-nancy-metz.fr', 'text', 'html ')
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\users\el_diablo\desktop\squid_log\parse.php on line 83


Procesadas: 0
Errores: 336
Promedio Errores: 100%
Inicio: 11/25/07 23:24:33 - Finalización: 11/25/07 23:24:34 - Duración: 0.016666666666667 Minutos

Ca un rapport avec mysql_affected_row(), Ma base et table sont ok alors aider moi svp!!! merci!!!

1 réponse

Messages postés
2483
Date d'inscription
jeudi 30 novembre 2006
Statut
Membre
Dernière intervention
14 janvier 2011
18
Salut,

Une lecture attentive du message d'erreur et de ton code donne la solution...

$res = mysql_query(....);

$res est donc une variable de type resource 'mysql result'.

Le message d'erreur dit :
"Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in..."

C'est pourtant clair : mysql_affected_rows() ne prend pas de résultat en paramètre.
http://fr.php.net/manual/fr/function.mysql-affected-rows.php

Si on passe un argument à mysql_affected_rows(), il faut que ce soit une resource de type 'mysql link'. Pas un résultat.
Si on ne passe pas d'argument, la fonction utilise la dernière connexion à MySQL.
Remplace

if (mysql_affected_rows($res))

par

if (mysql_affected_rows())