943,708 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 554
  • PHP RSS
May 23rd, 2009
0

Multile sql statement

Expand Post »
Hi,

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

Thanks

PHP Syntax (Toggle Plain Text)
  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. ?>
Similar Threads
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
May 23rd, 2009
1

Re: Multile sql statement

I thought that you could only run one query at a time in php. Have you checked the php manual for mysql functions?
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 945
Sarcastic Poster
ardav is offline Offline
6,678 posts
since Oct 2006
May 23rd, 2009
1

Re: Multile sql statement

Quote ...
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
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
May 23rd, 2009
0

Re: Multile sql statement

ok. I'll find different way then. Thanks guys.
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help, please?
Next Thread in PHP Forum Timeline: Global Methods





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC