Hiya all,
after my 1-2 weeks research i finally found a more consistent way to fire mysql queries in php i.e. transactions. I have two options to insert data in multiple tables ::
1) through procedures
2) through transactions
Of course i am going to prefer is the 2 way i.e. transactions. I went thru all the manuals of which Ronald gave me the links. But reading many forums and tutorials, i land up here again just to know why my code wont output the way i want. Just have a look at my code :
[PHP]
<?php
try {
$dbh = new PDO('mysql:host =localhost;port =3306;dbname=te st', 'root', '', array( PDO::ATTR_PERSI STENT => true));
$dbh->setAttribute(P DO::ATTR_ERRMOD E, PDO::ERRMODE_EX CEPTION);
$dbh->beginTransacti on();
$dbh->exec("update pop set age=1 where id=1");
$dbh->rollBack();
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>[/PHP]
It wont rollback, as written in code, it should not affect the age column of the table pop, because it meets the $dbh->rollback() function, but it will automaticaly commit.
please help me ..
I want the autoCommit thing to turn off using php.
cheers !!
Realin !
14 9032
i tried the conventional way, but even that wont help..
the change simply reflects in the database, it wont rollback :(
here is one more code, which i tried
[PHP]
<?php
$con=mysql_conn ect("localhost" ,"root","");
mysql_select_db ("test");
$res=mysql_quer y("START TRANSACTION",$c on);
if($res)
echo "transactio n started \n";
$res=mysql_quer y("update pop set age=90 where id=2");
if($res)
echo "Query Executed \n";
$res=mysql_quer y("ROLLBACK") ;
if($res)
echo "Rolled back";
?>[/PHP]
please help me thanks
please guys i need to know this ..
please
I think the AUTOCOMMIT statement has to do with this. The following sample works for me, so give it a try. I used a $debug variable to be able to switch between rollback and commit modes.[php]<?php
$debug=1;
$con=mysql_conn ect("localhost" ,"xxx","yyy" )
or die("Connect error: ".mysql_error() );
mysql_select_db ("zzz")
or die("Select db error: ".mysql_error() );
$res=mysql_quer y("SET AUTOCOMMIT=0",$ con)
or die("Set autocommit error: ".mysql_error() );
$res=mysql_quer y("START TRANSACTION",$c on)
or die("Start xact error: ".mysql_error() );
echo "transactio n started <br>";
$res=mysql_quer y("update a set yyyy='xest' where id > 5")
or die("Update error: ".mysql_query() );
echo "Query Executed <br>";
if ($debug) {
$res=mysql_quer y("ROLLBACK")
or die("Rollback error: ".mysql_query() );
echo "Rolled back<br>";
}
else {
$res=mysql_quer y("COMMIT")
or die("Commit error: ".mysql_query() );
echo "Committed<br>" ;
}
?>[/php]Ronald
code green 1,726
Recognized Expert Top Contributor
hiya ronald,
thanks for the reply, will go home and check it out..
much of thanks :)
hiya ronald,
thanks for the reply, will go home and check it out..
much of thanks :)
You are welcome. See you.
Ronald
hiya again Ronald,
Sorry to bother you, but this piece of code aint working for me..
here my System specs. - OS :: Windows Vista
-
Using XAMPP latest version so,
-
-
PHP Version 5.2.5
-
MYSQL Client API version 5.0.51a
I pasted your code, changed DB Details, and table details.. It showed Rolled back in browser but actually affected the databse :(
I am not actually able to perform transactions on mysql straight a way without having to use PHP even ..
What could be the problem ?
thanks for ur replies :)
cheers !!
Are the tables InnoDB?
hiya code green,
how do i check if my tables are innoDB or no..
cause i tried creating a new database and then executing the following command, and it should (as i believe) create a table under InnoDB engine,
please see if that is perfect ? - CREATE TABLE pop (id INT, age vachar (20), INDEX (id)) ENGINE=InnoDB;
thanks
Cheers!!
Realin !
############# EDIT ###############
hey hey,
i guess i got the issue here,
well i am using two tools to create tables and to manipulate mysql database, they are
Mysql query tools
phpmyadmin
Now when i fired the query (read from mysql website) - SHOW TABLE STATUS FROM test2 LIKE 'pop'
i could figure out that, the line of code written below does not create table under InnoDB engine, rather it creates table under MyISAM engine, which does not support TRANSACTIONS. - CREATE TABLE pop (id INT, age vachar (20), INDEX (id)) ENGINE=InnoDB;
pheeeeeeeeewwww w (deep breathe)
Well, i guess now i gotta search a way to make tables in InnoDB instead of MyISAM engine..
When i try altering the table, it just do not let me do that and instead gives an error saying 2014 Commands out of sync; you can't run this command now
well, if some gets to know, what this all is happening, i will be thankful :)
Ronald, i really thank you mann for every single LOC :0
thanks & cheers to every1 :)
Realin !
All right,
I m trying it from command line, even then i am unable to create a table under InnoDB engine, well why so ?
trust me, i never bothered about the engine in the last 2 years :p
Now i come to know, why these things are brought into existence .. hehehe .. :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Lodewijk Voge |
last post by:
hello,
MySQL lets CURRENT_TIMESTAMP tick on inside transactions. I'm
wondering why? doesn't this violate the atomicity of transactions?
thank you,
Lodewijk
|
by: Thomas Svenson |
last post by:
I'm looking for any online resources/tutorials and such about transactions.
Preferable for MySQL, but others will do.
Other than that, is there any good book about transactions. Again preferable
for MySQL.
/T
--
|
by: Marc Slemko |
last post by:
Suppose I have an innodb table in 4.0.14 and do:
LOCK TABLE maggie
INSERT INTO maggie values(123, 'simpson');
UNLOCK TABLES
As soon as I issue LOCK TABLE, any transaction in progress is
automatically committed.
By what point is this INSERT guaranteed to be committed to disk
|
by: Heikki Tuuri |
last post by:
Hi!
Many people have complained over years that Borland's dbExpress driver does
not work with MySQL and transactions, because it disconnects from mysqld
after each SQL statement. The postings below suggests that this problem
might now be fixed by Borland.
Best regards,
Heikki Tuuri
|
by: Slav |
last post by:
Hello,
I'm trying to port the use of postgresql db to mysql. I'm using
Java and having the following problem - I can't seem to write more
than 1 query per execution. Easier to explain with an example that
worked under postgresql and does not using mysql:
aStatement.executeQuery("BEGIN; DELETE FROM table1; DELETE FROM
table1; DELETE FROM table3; COMMIT;");
| |
by: princevejita1 |
last post by:
Hello
I have problem with my MySQL server and transactions. I installed MySQL
server 5.0.11 with MySQL administrator & MySql Query Browser on Win XP
Prof. I would like to use transactions, so I have read the manual ana I
thought I knew how to do it. I set the tables type to InnoDB (i can't
use BDB) and change the default mysqld.exe to mysql-max (or
mysql-max-nt). I even used : SET AUTOCOMMIT=0.
I'm doing more less this:
1. START...
|
by: John Wells |
last post by:
On this page: http://www.compiere.org/technology/independence.html, the
project leader of Compiere (a popular ERP package) states that the move to
Postgres failed because of lack of support of embedded
transactions...something both Oracle and DB2 support.
Can someone explain to me excactly what embedded transactions are and why
they're challenging enough to not be included in Postgres or MySQL? I'm
guessing it's some sort of...
|
by: saran |
last post by:
I am having a problem with MySQL consuming a lot of memory and
eventually throwing an Out of Memory error and restarting itself. The
symptoms are that swap usage continues to rise until some breaking
point. The application is a typical web application w/ 2 web servers
running Apache/Tomcat connecting to a dedicated DB server running only
MySQL.
This seems to occur as a result of running many statements in a single
transaction, both...
|
by: =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= |
last post by:
Hi there guys,
My doubt is related with MySQL and Transactions (InnoDB) so here it
goes:
I have a query like this:
$query = 'START TRANSACTION; ';
$query .= 'UPDATE sections ';
$query .= 'SET position=position-%d ';
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |