DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Multile sql statement (http://www.daniweb.com/forums/thread193532.html)

veledrom May 23rd, 2009 6:07 am
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";
        }
}
?>

ardav May 23rd, 2009 8:45 am
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?

nav33n May 23rd, 2009 2:59 pm
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

veledrom May 23rd, 2009 4:42 pm
Re: Multile sql statement
 
ok. I'll find different way then. Thanks guys.


All times are GMT -4. The time now is 10:15 pm.

Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC