Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. $bd->conectar($mysql_host,$mysql_user,$mysql_password);
  2. $bd->selBD($mysql_database);
  3.  
  4. $query = "Select * FROM alumnos";
  5. $vecID = array();
  6. $bd->qBD($query);
  7. while ($vec = $bd->obtenerReg()){
  8. $vecID[] = $vec[0];
  9. }
  10.  
  11. foreach ($vecID as $varId) {
  12.  
  13. $query = "Select id_alumno,foto,foto_name,foto_type , OCTET_LENGTH(foto) size FROM alumnos WHERE tramite_id = ".$varId;
  14. $bd->qBD($query);
  15. if ($vec = $bd->obtenerReg()){
  16. $archivo = $vec[1];
  17.  
  18. if($vec[4]>0){ // me interesa el campo 'foto' por eso pregunto vec[4]
  19. $dbconn = pg_connect("host=127.0.0.1 port=8080 dbname=prueba user=postgres password=123123")
  20. or die('Could not connect: ' . pg_last_error());
  21.  
  22. $result_max = @pg_query($dbconn, "Select MAX(cdsu_id) FROM documentacion_alumno WHERE id_alumno = '".$vec[0]."'"); // cuento la cantidad de archivos que tiene subida en esa tabla
  23.  
  24. if($result_max !== FALSE) {
  25. $num_rows = @pg_num_rows($result_max);
  26.  
  27. if ( $num_rows !== 0 ) {
  28. while ($row = pg_fetch_row($result_max)) {
  29. $id_max = $row[0];
  30. }
  31. $id_max = $id_max + 1;
  32. $escaped = pg_escape_bytea($archivo);
  33. $result_insert = pg_query($dbconn,"INSERT INTO documentacion_alumno (cdsu_id_alumno, cdsu_id, cdsu_id_tipoadjunto, cdsu_fechasubida, cdsu_nota, cdsu_doc, cdsu_nombre, cdsu_tipo, cdsu_size) "
  34. ."VALUES (".$vec[0].", ".$id_max.", 1, '".date('Y-m-d')."', 'Migracion', '{$escaped}', '".$vec[2]."', '".$vec[3]."', ".$vec[4].")");
  35. }
  36. }
  37. }
  38.  
  39. function obtenerReg()
  40. {
  41. if ($this->numFilas>0) {
  42. $this->numFilas--;
  43. return mysqli_fetch_row($this->result);
  44. }
  45. else return false;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement