Next.js and MySQL
Answered
Router Renegade posted this in #help-forum
hey, In NextJS, how can I make it such that Data should come from MySQL database when a button is clicked? I am using Prisma ORM?
Is it ideal to use the CRUD operation?
Is it ideal to use the CRUD operation?
Answered by B33fb0n3
you can either use a server action or route handlers. However using server actions there are some disadvantages with it, so you might want to use route handlers to fetch data onClick. Keep in mind to use a clientside fetching library like react query or swr
14 Replies
@Router Renegade hey, In NextJS, how can I make it such that Data should come from MySQL database when a button is clicked? I am using Prisma ORM?
Is it ideal to use the CRUD operation?
you can either use a server action or route handlers. However using server actions there are some disadvantages with it, so you might want to use route handlers to fetch data onClick. Keep in mind to use a clientside fetching library like react query or swr
Answer
@Router Renegade Thanks
Happy to help. Please mark solution
@B33fb0n3 Happy to help. Please mark solution
how to mark?
I am new to this server 

yes, that worked 👍
@B33fb0n3 you can either use a server action or route handlers. However using server actions there are some disadvantages with it, so you might want to use route handlers to fetch data onClick. Keep in mind to use a clientside fetching library like react query or swr
Hey, btw Can i also Server actions such that the data coming from sql is shown as a table in the frontend?
@Router Renegade Hey, btw Can i also Server actions such that the data coming from sql is shown as a table in the frontend?
Yes you can and after fetching you can render the data as table