Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should I insert data into table using php or my sql [closed]

I was wondering should I use procedures in mySql or direct from php to populate the table named Project. I have $projectName, $startDate etc. should I call a mySql procedure or directly using php?

For example:

        $queryInsert ="INSERT INTO users  (name) 
        VALUES('".$projectName."')";
        //and so on for the rest of vars

Wondering which is the best coding practice method to use. thanks

like image 777
Cormac Hallinan Avatar asked May 07 '26 10:05

Cormac Hallinan


1 Answers

Some benefits of stored procedure are :

  • Maintainability: you can change the logic in the procedure without needing to edit app1, app2 and app3 calls.
  • Security/Access Control: it's easier to worry about who can call a predefined procedure than it is to control who can access which tables or which table rows.
  • Performance: if your app is not situated on the same server as your DB, and what you're doing involves multiple queries, using a procedure reduces the network overhead by involving a single call to the database, rather than as many calls as there are queries.
  • Performance (2): a procedure's query plan is typically cached, allowing you to reuse it again and again without needing to re-prepare it.
like image 85
Creative Learner Avatar answered May 09 '26 22:05

Creative Learner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!