Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-05-2006, 11:08 PM
|
#1
|
Member
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233
Rep:
|
php+mysql: how to execute a sql batch file
Hello everybody,
I have deveoped a portal using apache+php+mysql.
invoking mysql query through the php mysql_query fucntion is alright, but if I have to send three or four queries (say as a batch file), what should I do ?
Say I have to send:
locak tables mytable write;
update mytable set myfield="myvalue";
unlock tables;
One mehtod is that I should invoke mysq_query function for all the three queries seperately one after another. But I feel, that would inefficient, and there should be some better way.
Am I right ?
What other better alrtnatives are available.
Any guidance would be welcome.
Thanks in advance.
Prabhat Soni
|
|
|
04-06-2006, 05:33 AM
|
#2
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
Can't you create a stored procedure in MySql that does what you want and then
execute it in PhP as a normal query?
|
|
|
04-13-2006, 12:13 AM
|
#3
|
Member
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233
Original Poster
Rep:
|
Hi folks,
I am sorry I am late. In fact, I was out of town for las few days.
Can you elaborate that "stored Proceedure" part. I feel the situation that I have encountered is not at all so un-common. php+mysql+apache is a very potent combination and the same must definitely be serving very high volume os traffick, making table-locking or sql-scripts unavoidable. Prbabley the stored proceedures as suggested is the answer. I would request you to please elaborate on the same.
Thanks in advance.
Prabhat Soni
|
|
|
04-13-2006, 01:39 AM
|
#4
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
A stored procedure is a block of SQL code, enclosed in BEGIN and END tags.
Check out
http://dev.mysql.com/doc/refman/5.0/...rocedures.html
for the MySql syntax.
|
|
|
04-15-2006, 06:44 AM
|
#5
|
Member
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233
Original Poster
Rep:
|
Thanks a lot for your valuable pointers.
I believe stored procedures would suit the bill.
Unfortunately the same is not available in the mysql 4.1, which is the what I have.
I will think of upgrading in near future.
Thanks nevertheless for your help.
Prabhat Soni
|
|
|
04-18-2006, 01:55 AM
|
#6
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
Don't forget to use mysqldump to create a backup of all your databases before you upgrade,
just to be on the safe side.
|
|
|
04-18-2006, 07:21 PM
|
#7
|
LQ Newbie
Registered: Sep 2003
Location: UK
Distribution: FC7
Posts: 27
Rep:
|
the MySQL C API's mysql_query() function (as used in PHP) is quite intentionally designed to only allow one query at a time. So, without procedures, there's no real way to do it directly within PHP without some nasty shell_exec()/backtick calls to MySQL
|
|
|
04-19-2006, 06:11 AM
|
#8
|
Member
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233
Original Poster
Rep:
|
Sir,
Please elabotrate !
Thanks
Prabhat Soni
|
|
|
All times are GMT -5. The time now is 02:30 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|