pg_close()错误? 是关闭2连接的子关闭?

I am currently getting this error: pg_close(): 12 is not a valid PostgreSQL link resource. This is the code that is being executed:

    function getProyectosDeUsuarioDAO($idUsuario)
{
    $conexion = conectar();
    $consulta = "sql things here;";
    $resultado = pg_query($consulta) or die('Consulta fallida: ' . pg_last_error());
    $lista = array();

    $lista = pg_fetch_all($resultado);
    var_dump($lista);
    $listaProyectos = array();
    if(!empty ($lista))
    {
        foreach ($lista as $p)
        {

            $proyecto = new Proyecto();

            $proyecto->setNombre($p['nombre']);
            $proyecto->setFechaInicio($p['fechainicio']);
            $proyecto->setFechaFin($p['fechafin']);
            $proyecto->setId($p['id']);
            //Cargar roles del usuario para cada proyecto
            $proyecto->setRoles(getRolesByProyecto($proyecto->getId(),$idUsuario));

            array_push($listaProyectos, $proyecto) ;
        }

        if($conexion)
        {
             pg_close($conexion); //##############error here#################
        }
        pg_free_result($resultado);
        var_dump($listaProyectos);  
        return $listaProyectos;
    }

var_dumps are made to check if the query is working and it does work; I am not sure how to debug this.

I am using php_pgsql and WAMP server ($conexion) works for checking, however I'm not sure if connection is live or not?