multi-query

PHP PDO Transactions?

一曲冷凌霜 提交于 2019-12-02 15:09:19
I have a signup page and basically I need data inserted into 4 tables. I'm new to PDO and am confused over something. Basically if any of the inserts fail I don't want anything added to the database, that seems simple enough. My confusion is, I need to first insert the users username, email, password etc in my users table so I can get (not sure how) using PDO the uid MySQL has given my user (auto incremented by mysql). I need the user uid MySQL gave my user for the other tables as the other tables needs the uid so everything is linked properly together. My tables are InnoDB and I have foreign

mysqli multiple queries - set variable produces boolean error/how to skip this?

怎甘沉沦 提交于 2019-12-02 03:22:23
问题 Got the following simple query which works fine through phpmyadmin but when I add it to my php website no results are returned and no error/warning messages either. If I remove "SET @N=-1;" then it works fine. <?php $db_connect = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true); mysql_select_db(DB_NAME, $db_connect); $test_query = mysql_query("SET @N=-1;SELECT `id`, (@N:=@N+1) AS `mycount` FROM `mydb`;"); for ($i = 0; $i <= mysql_num_rows($test_query)-1; $i++) { echo mysql_result($db

mysqli multiple queries - set variable produces boolean error/how to skip this?

佐手、 提交于 2019-12-01 23:37:27
Got the following simple query which works fine through phpmyadmin but when I add it to my php website no results are returned and no error/warning messages either. If I remove "SET @N=-1;" then it works fine. <?php $db_connect = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true); mysql_select_db(DB_NAME, $db_connect); $test_query = mysql_query("SET @N=-1;SELECT `id`, (@N:=@N+1) AS `mycount` FROM `mydb`;"); for ($i = 0; $i <= mysql_num_rows($test_query)-1; $i++) { echo mysql_result($db_directorymap, $i, 0) . " " . mysql_result($db_directorymap, $i, 1) . "<br />"; } ?> UPDATE: I just moved to

“Commands out of sync; you can't run this command now” - Caused by mysqli::multi_query

帅比萌擦擦* 提交于 2019-11-28 03:16:48
问题 I am running multiple deletes through mysqli::multi_query and it is messing up the next query in line.The following error is being thrown. Error - SQLSTATE HY000. Sql error: Commands out of sync; you can't run this command now Do I need to somehow clear the multiquery so it doesn't mess with my next query? What is the cause of this error? And this is how I am running my multiquery function deleteSomeTables($args){ $sql = 'delete 1;delete another;'; if($database->multi_query($sql)){ return