Solved

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

Posted on 2016-09-08
6
57 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 30

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress Query 1 34
php documentation 4 21
php variable basic question 12 27
using hash in login 34 13
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now