Re: MySQL question
On 7/21/06, Karjala [EMAIL PROTECTED] wrote: Maybe I should ask this question on a database list, but it's related to DBI, so I'm asking here also: I have a field in a record in the MySQL database that contains a number. I increase it by one with $dbh-do(update table set myfield = myfield + 1 where mykey = 10); I was wondering whether there's a way to find out the value of myfield right after the update. Running a select myfield right after the update is not a good enough solution to my problem, since this is a web-based application, and therefore it's possible that myfield might increase again between the time of the first update and the select. Do you know of any solution to this problem? http://dev.mysql.com/doc/refman/4.1/en/ansi-diff-transactions.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: MySQL question
If you have MySQL 5.0 or greater, you will be able to create a stored procedure and call it from DBI. with warm regards, Venkat Saranathan Gulf Breeze Software www.gulfsoft.com GulfBreeze Blog www.gulfsoft.com/blog -Original Message- From: Karjala [mailto:[EMAIL PROTECTED] Sent: Friday, July 21, 2006 7:54 PM To: beginners@perl.org Subject: MySQL question Maybe I should ask this question on a database list, but it's related to DBI, so I'm asking here also: I have a field in a record in the MySQL database that contains a number. I increase it by one with $dbh-do(update table set myfield = myfield + 1 where mykey = 10); I was wondering whether there's a way to find out the value of myfield right after the update. Running a select myfield right after the update is not a good enough solution to my problem, since this is a web-based application, and therefore it's possible that myfield might increase again between the time of the first update and the select. Do you know of any solution to this problem? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Mysql Question. Can Someone Help
Hello Fellow Members, Howdy I am new to perl and Mysql. I want to set up a mysql table to take Email addresses, and randomly place them into a payment button from PayPal, and StormPay. Can anyone tell me how to write the script to setup the MySql Table to do this. Sure, you need to be familiar with the DBI module first off. Create your table and a user to SELECT from it. Look at the examples in perldoc DBI for how to do a multiple row SLEECT query. Get the query : SELECT Email from PayPalAccounts into an array, say @PPEmail then grab one at random like so: my $email = $PPEmail[rand @PPEmail]; print qq(input type=hidden name=Account value=$email\n); HTH DMuey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
OT: RE: Mysql Question. Can Someone Help
On Wed, 27 Aug 2003 09:25:03 -0500, Dan Muey [EMAIL PROTECTED] wrote: Hello Fellow Members, Howdy I am new to perl and Mysql. I want to set up a mysql table to take Email addresses, and randomly place them into a payment button from PayPal, and StormPay. Can anyone tell me how to write the script to setup the MySql Table to do this. Sure, you need to be familiar with the DBI module first off. Create your table and a user to SELECT from it. Look at the examples in perldoc DBI for how to do a multiple row SLEECT query. Get the query : SELECT Email from PayPalAccounts into an array, say @PPEmail then grab one at random like so: my $email = $PPEmail[rand @PPEmail]; print qq(input type=hidden name=Account value=$email\n); Though Dan's method is probably more portable, MySQL (3.23+) has a RAND function for selecting a random set when used with an ORDER BY and a LIMIT, which will be more efficient and less memory intensive than selecting all rows for larger datasets. Check the MySQL docs. Then you apply the same DBI methods Dan mentioned though don't have to worry about randomizing them, etc. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mysql Question. Can Someone Help
Hello Dan, Howdy, please respond to the list and not just me so everyone can help/learn. Thanks for the come back. I decided to accept PayPal and StormPay. I would need to collect the PayPal Email, StormPay Email, and the peoples name for a form to the MySql Table Correct? Would this work? To Create Table. use CGI::Carp qw(fatalsToBrowser); # MySQL (Database) Information $sql_db_name = randomizer; $sql_user = randomizer; $sql_pass = biz123; $sql_hostname =; $sql_port =; Db_Connect; Why two calls to Db_Connect? Use my() variables to keep from shooting yourself in the foot. Use strict and warnings/-w switch. $SQL = CREATE TABLE randomizer ( Name varchar(40), PayPal varchar(40), StormPay varchar(25), ); Go_SQL; Why not just use do() to simplitfy and check the return value? Db_Connect; $SQL = INSERT INTO randomizer (Name,PayPay,StormPay) VALUES ('admin','[EMAIL PROTECTED]','[EMAIL PROTECTED]''); Go_SQL; $sth-finish; $dbh-disconnect; I didn't see this declared earlier, another reason to use strict and my and use module functions instead of your own function that just runs that one function basically. print Content-type: text/html\n\n; print font face=\$def_font\ size=\$def_fsize\\n; print p align=\center\font size=\5\ face=\Arial Black\ color=\$name_clr\Randomizer/font/p\n; print p align=\center\nbsp; nbsp; /p\n; print center\n; print BSuccessfully Setup The MySQL Database!/BPThe How do you know it was successful you didn't check any return values? table \randomizer\ was created for you within your database :)HR ALIGN=\LEFT\ WIDTH=\70%\; print PA Randomizer account was also setup for admin, your login information is...pUsername: adminbrPassword: adminpassp; print bRemove, Delete or Rename this file now, It's No Longer Needed For The List To Run!/b; print /center\n; exit; Exit at the end of the script is pointless and possibly bad, like in mod_perl env. How about somethgin like this: #!/usr/bin/perl -w use strict; use CGI qw(header); use DBI; print header(); my $dbh = DBI-connect(...) or die connect failed $DBI::errstr; my $rc = $dbh-do(CREATE TABLE ...) or die create table failed $DBI::errstr; die 0E0 error on table create if $rc =~ m/^0E0$/; $dbh-disconnect(); print Well I made it this far without dieing I must be ok!; See how much more readable it is? Also in a year or so when you or somebody else comes along it's easy to figure out what's going on. If So, Then how do I call it to random place the PayPal, StormPay addresses into the buttons. There was my original idea: Select all address into a list and choose a random one. Or Get one address from a query that returns a random one out of all of them. #2 would be better on memory and speed too I would assume since the script only has to work with 1 piece of data insead of building a list then choosing from it. Either way, get the data and put it in your form. HTH DMuey Thanks in Advance Dan - Original Message - From: Dan Muey [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, August 27, 2003 10:25 AM Subject: RE: Mysql Question. Can Someone Help Hello Fellow Members, Howdy I am new to perl and Mysql. I want to set up a mysql table to take Email addresses, and randomly place them into a payment button from PayPal, and StormPay. Can anyone tell me how to write the script to setup the MySql Table to do this. Sure, you need to be familiar with the DBI module first off. Create your table and a user to SELECT from it. Look at the examples in perldoc DBI for how to do a multiple row SLEECT query. Get the query : SELECT Email from PayPalAccounts into an array, say @PPEmail then grab one at random like so: my $email = $PPEmail[rand @PPEmail]; print qq(input type=hidden name=Account value=$email\n); HTH DMuey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]