Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $bd->conectar($mysql_host,$mysql_user,$mysql_password);
- $bd->selBD($mysql_database);
- $query = "Select * FROM alumnos";
- $vecID = array();
- $bd->qBD($query);
- while ($vec = $bd->obtenerReg()){
- $vecID[] = $vec[0];
- }
- foreach ($vecID as $varId) {
- $query = "Select id_alumno,foto,foto_name,foto_type , OCTET_LENGTH(foto) size FROM alumnos WHERE tramite_id = ".$varId;
- $bd->qBD($query);
- if ($vec = $bd->obtenerReg()){
- $archivo = $vec[1];
- if($vec[4]>0){ // me interesa el campo 'foto' por eso pregunto vec[4]
- $dbconn = pg_connect("host=127.0.0.1 port=8080 dbname=prueba user=postgres password=123123")
- or die('Could not connect: ' . pg_last_error());
- $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
- if($result_max !== FALSE) {
- $num_rows = @pg_num_rows($result_max);
- if ( $num_rows !== 0 ) {
- while ($row = pg_fetch_row($result_max)) {
- $id_max = $row[0];
- }
- $id_max = $id_max + 1;
- $escaped = pg_escape_bytea($archivo);
- $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) "
- ."VALUES (".$vec[0].", ".$id_max.", 1, '".date('Y-m-d')."', 'Migracion', '{$escaped}', '".$vec[2]."', '".$vec[3]."', ".$vec[4].")");
- }
- }
- }
- function obtenerReg()
- {
- if ($this->numFilas>0) {
- $this->numFilas--;
- return mysqli_fetch_row($this->result);
- }
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement