Multile sql statement

Reply

Join Date: Apr 2008
Posts: 510
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro

Multile sql statement

 
0
  #1
May 23rd, 2009
Hi,

What is wrong with this sql? It fails in php but doesn't fail in phpmyadmin!

Thanks

  1. <?php
  2. $connection=mysql_connect("localhost", "root", "");
  3. if(!$connection) {
  4. die('Could not connect: ' . mysql_error());
  5. } else {
  6. mysql_select_db("test", $connection) or die('Could not select the table.');
  7.  
  8. $sql="BEGIN;\n";
  9. $sql.="SET AUTOCOMMIT=0;\n";
  10. $sql.="INSERT INTO table1 (id, name) values (1, 'person1');\n";
  11. $sql.="INSERT INTO table2 (id, name) values (2, 'person2');\n";
  12. $sql.="INSERT INTO table3 (id, name) values (3, 'person3');\n";
  13. $sql.="COMMIT;";
  14. /*echo "<pre>";
  15. echo $sql;exit;*/
  16. $runSql=mysql_query($sql);
  17.  
  18. if($runSql) {
  19. echo "Done";
  20. } else {
  21. echo "Failed";
  22. }
  23. }
  24. ?>
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,087
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 137
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: Multile sql statement

 
1
  #2
May 23rd, 2009
I thought that you could only run one query at a time in php. Have you checked the php manual for mysql functions?
If you don't reply to your own thread or you can't find the solved link - you're off my Christmas list - permanently! Bah humbug!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Multile sql statement

 
1
  #3
May 23rd, 2009
mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .
Source: http://in2.php.net/function.mysql-query
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 510
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro

Re: Multile sql statement

 
0
  #4
May 23rd, 2009
ok. I'll find different way then. Thanks guys.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 413 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC