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";
	}
}
?>
Member Avatar for diafol

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

commented: Thanks +2

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

commented: Thanks +2

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.