title: What is the difference between sqlx.Connect() and sqlx.Open()?
body: <p>I am using <a href="https://github.com/jmoiron/sqlx" rel="nofollow noreferrer">jmoiron sqlx</a> library for my golang project. I tried to create a db connection mysql. So, I found these two functions: <code>sqlx.Connect()</code> and <code>sqlx.Open()</code>, but didn't found the difference.</p>
  
  <p>So, I tried to read the documentation in <a href="https://godoc.org/github.com/jmoiron/sqlx" rel="nofollow noreferrer">godoc</a>. I found this:</p>
  
  <p><strong>sqlx.Connect()</strong></p>
  
  <pre><code>Connect to a database and verify with a ping.
  </code></pre>
  
  <p><strong>sqlx.Open()</strong></p>
  
  <pre><code>Open is the same as sql.Open, but returns an *sqlx.DB instead.
  </code></pre>
  
  <p>I know that <code>sqlx.Open()</code> create a connection to the database using golang <code>sql.Open</code>. But what is <code>sqlx.Connect()</code> use?</p>
  
  <p>If I see inside the source code here:</p>
  
  <pre><code>func Connect(driverName, dataSourceName string) (*DB, error) {
      db, err := Open(driverName, dataSourceName)
      if err != nil {
          return nil, err
      }
      err = db.Ping()
      if err != nil {
          db.Close()
          return nil, err
      }
      return db, nil
  }
  </code></pre>
  
  <p>I can see that it called the same <code>sqlx.Open()</code> then calling <code>db.Ping()</code>. So the the only difference is that <code>sqlx.Open()</code> execute ping after create connection? If so, why it does ping? What makes it different?</p>
  
  <p>Thank you</p>