LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 04-05-2006, 11:08 PM   #1
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Rep: Reputation: 30
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
 
Old 04-06-2006, 05:33 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Can't you create a stored procedure in MySql that does what you want and then
execute it in PhP as a normal query?
 
Old 04-13-2006, 12:13 AM   #3
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
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
 
Old 04-13-2006, 01:39 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 04-15-2006, 06:44 AM   #5
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
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
 
Old 04-18-2006, 01:55 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Don't forget to use mysqldump to create a backup of all your databases before you upgrade,
just to be on the safe side.
 
Old 04-18-2006, 07:21 PM   #7
mrjamin
LQ Newbie
 
Registered: Sep 2003
Location: UK
Distribution: FC7
Posts: 27

Rep: Reputation: 15
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
 
Old 04-19-2006, 06:11 AM   #8
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Sir,
Please elabotrate !


Thanks


Prabhat Soni
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL SQL file too big? fieldyweb Programming 3 01-23-2006 09:44 PM
mysql batch file won't work... bug? Red Squirrel Linux - Software 8 08-23-2004 05:01 PM
SQL queries per page (PHP, MySQL) Silent1 Programming 2 06-27-2004 11:15 PM
How do I get a dump file (.sql) into MySql? TreeDragon60 Linux - Software 4 03-21-2004 05:19 AM
SQL mySQL PHP and Sessions poeta_boy Programming 15 11-26-2003 06:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration