# UndefRefError - Trying access variable inside for

**URL:** https://discourse.julialang.org/t/undefreferror-trying-access-variable-inside-for/106963
**Category:** General Usage
**Tags:** question, mysql
**Created:** [November 30, 2023, 8:30pm UTC](https://discourse.julialang.org/t/undefreferror-trying-access-variable-inside-for/106963 "2023-11-30T20:30:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![th.simoes](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@th.simoes](https://discourse.julialang.org/u/th.simoes)
#### Post date: [November 30, 2023, 8:30pm UTC](https://discourse.julialang.org/t/undefreferror-trying-access-variable-inside-for/106963/1 "2023-11-30T20:30:10Z")

</div>

I’m using DBInterface and MySQL to interact with my MySQL database, but my function is stucking into a strange error.

This function below works well, but is slow and inefficient:

```julia
function insertNewDebDataIntoDatabase(df::DataFrame)
    conn::DBInterface.Connection = getConnection()
    
    for row in eachrow(df)
        query = DBInterface.prepare(
            conn,
            "INSERT INTO DebSchedule ..."
        )
        DBInterface.execute(
            query, [
            row[:RptDt],...])
        DBInterface.close!(query)
    end

end

```

But this below doesn’t work:

```julia
function insertNewDebDataIntoDatabase(df::DataFrame)
    conn::DBInterface.Connection = getConnection()
    query = DBInterface.prepare(
            conn,
            "INSERT INTO DebSchedule ..."
        )
    
    for row in eachrow(df)
        
        DBInterface.execute(
            query, [
            row[:RptDt],...])
    end
    DBInterface.close!(query)

end

```

This throws `ERROR: UndefRefError: access to undefined reference`.  
I don’t see why the difference between them could be a problem.
