954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Multile sql statement

Hi,

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

Thanks

<?php
$connection=mysql_connect("localhost", "root", "");
if(!$connection) {
	die('Could not connect: ' . mysql_error());
} else {
	mysql_select_db("test", $connection) or die('Could not select the table.');

	$sql="BEGIN;\n";
	$sql.="SET AUTOCOMMIT=0;\n";
	$sql.="INSERT INTO table1 (id, name) values (1, 'person1');\n";
	$sql.="INSERT INTO table2 (id, name) values (2, 'person2');\n";
	$sql.="INSERT INTO table3 (id, name) values (3, 'person3');\n";
	$sql.="COMMIT;";
	/*echo "<pre>";
	echo $sql;exit;*/
	$runSql=mysql_query($sql);
	
	if($runSql) {
		echo "Done";
	} else {
		echo "Failed";
	}
}
?>
veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

I thought that you could only run one query at a time in php. Have you checked the php manual for mysql functions?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
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

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

ok. I'll find different way then. Thanks guys.

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You