Solved

Can Create single (dynamic)  store procedure for Insert,Update, Delete of 100 of tables.

Posted on 2016-09-08
6
64 Views
Last Modified: 2016-09-26
Hello,
 I want to create single store procedure in php mysql for all operations. Where I want pass all parameters including table name and column name. I don't want to create 100 procedure for my 100 table. Insted of creating 100 procedure want to create single procedure where i can perform my 100 tables operations.
0
Comment
Question by:Pravin Bnakar
6 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 41790769
And what's hindering you? You create an sql string and send it to MySQL, you can compose it as needed.
Have a look at ActiveRecord (as used by Laravel, for example): http://www.phpactiverecord.org/

Bye, Olaf.
1
 

Author Comment

by:Pravin Bnakar
ID: 41790778
I am not getting what you want to say.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 41790781
ActiveRecord does what you want to do. Take a look at its source code. Or simpler: Take it and use it.

Bye, Olaf.
1
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41790855
If you do not understand the meaning of the Active Record design pattern and you're not willing to invest the time to learn it, you might want to consider using E-E Gigs.  You can get a professional programmer to help you with the details of the implementation!  

Your required solution may not have to be the classic AR design pattern; it may be possible to use any of a number of CRUD-type abstraction layers.  But I think Olaf has you on the right track.
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 41790861
AFAIK a stored procedure can't include more than one single op: you can have a stored procedure for SELECT, one for INSERT and so on.
So you can use ActiveRecord and use its abstraction to do the same thing.
Alternatively, you could write your own class with methods to do exactly what you want. You could modify a class like this one: http://code.tutsplus.com/tutorials/create-a-php5-framework-part-2--net-805
or just keep it as it is and use it in a loop for all 100 tables.

Maybe you can be more specific in your question to help us to give you better answers :)
1
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 41791047
In fact ActiveRecord does not work with Stored Procs, but prepared PDO Statements. I still recommend this, because you don't really profit from 100 of stored procs nor 1 stored proc. I can reuse this for the third time now, to spare my time: http://www.joinfu.com/2010/05/mysql-stored-procedures-aint-all-that/

Prepared statements give you all the advantages you may get from stored procs "only" anyway. And a single stored proc can only do the same as ActiveRecord does, build up an sql command string and prepare/execute it.

Bye, Olaf.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now