| Start |
|---|
| Connect to MySQL One of the easiest ways to connect to MySQL is by using Now you have to create a mysql connection, which you can later query. In the next example you will learn how to query the |
Using a connection pool a. Running multiple queries at same timeAll queries in MySQL connection are done one after another. It means that if you want to do 10 queries and each query takes 2 seconds then it will take 20 seconds to complete whole execution. The solution is to create 10 connection and run each query in a different connection. This can be done automatically using connection pool It will run all the 10 queries in parallel. When you use b. Achieving multi-tenancy on database server with different databases hosted on it.Multitenancy is a common requirement of enterprise application nowadays and creating connection pool for each database in database server is not recommended. so, what we can do instead is create connection pool with database server and then switch them between databases hosted on database server on demand. Suppose our application has different databases for each firm hosted on database server. We will connect to respective firm database when user hits the application. Here is the example on how to do that:- Let me break down the example:- When defining pool configuration i did not gave the database name but only gave database server i.e so when we want to use the specific database on database server, we ask the connection to hit database by using:- you can refer the official documentation here (opens new window) |
| Query a connection object with parameters When you want to use user generated content in the SQL, it with done with parameters. For example for searching user with the name |
| Query a connection object without parameters You send the query as a string and in response callback with the answer is received.
The callback gives you |
| Run a number of queries with a single connection from a pool There may be situations where you have setup a pool of MySQL connections, but you have a number of queries you would like to run in sequence: You could just run then using You can, however, retain an active connection from the pool and run as many queries as you would like using a single connection using Note: You must remember to For more information on pooling MySQL connections check out the MySQL docs (opens new window). |
Export Connection Pool |
| Return the query when an error occurs You can attach the query executed to your |
Read Article
https://develop.horje.com/learn/1434/reference