Re: [PHP-DB] transactions and persitent connections
At 12:52 +0900 9/1/02, Jean-Christian Imbeault wrote: Paul Dubois wrote: I am worried that if I use persistent connections it might be possible for more than one PHP script to be inside the same transaction at the same time. Not at the *same* time, because although a persistent connect might be used by more than one script, this will be serially rather than simultaneously. That does mean it's possible for a transaction to be started by one script and then either committed or rolled back by the next if they share a connection. That's exactly what I meant and feared. In a sense User 2 who is re-using User 1's connection would be in User 1's un-completed transaction. And the result of User 2's transaction (commit or rollback) would affect the first transaction. Yuck ... 2- If user 1's hits the stop button on his browser, what happens to his transaction? I assume it is stopped. But what about the connection? If user 2 No, the script won't have any idea the stop button has been pressed. It should have executed and completed its transaction regardless of what the user does. Really? I don't exactly know how PHP script execute but I though that is that the user goes to a page that starts a script and then closes the browser that causes the script to end prematurely. The script doesn't know anything about what the browser does. Am I wrong? Yes. Does the script go from start to finish even though the connection to the browser has been severed. I.e. The script will run complete even if there is output to the browser as the script is running? Not necessarily. It won't base its actions on what the browser might happen to be doing while it's running, but it might exit early because of a bug, for example. But normally it will run to completion. If the script goes from start to finish regardless of what the user does that would be nice. That way I am sure a transaction will go from start to finish, and if I make sure to either commit or rollback the transaction at the end of the script then I don't have to worry. You should write your script so that is *does* go from start to finish. Forget about what the user might be doing. Maybe the safest thing to do is not use persistent connections at all? Or in your opinion is there a safe way to use persistent connections and transactions? No. Don't use persistent connections. If some unforeseen problem does occur with your script, the connection may be left open and you'll have the problems you're concerned about. If you use a non-persistent connection and a problem occurs, the connection will be closed (which presumably will make your transaction roll back). Jc PS Great book! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] transactions and persitent connections
Paul Dubois wrote: Does the script go from start to finish even though the connection to the browser has been severed. I.e. The script will run complete even if there is output to the browser as the script is running? Not necessarily. It won't base its actions on what the browser might happen to be doing while it's running, but it might exit early because of a bug, for example. But normally it will run to completion. Thanks for clearing that up for me. You should write your script so that is *does* go from start to finish. Forget about what the user might be doing. Trying *very* hard. No. Don't use persistent connections. If some unforeseen problem does occur with your script, the connection may be left open and you'll have the problems you're concerned about. If you use a non-persistent connection and a problem occurs, the connection will be closed (which presumably will make your transaction roll back). Thanks. With what you've explained I understand the pitfalls persistent connections might and will not be using them. Such a shame ... Thanks again for all the information! Jc -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] uploading images before creating db entry
Hi there, I have a running system where users can upload images. Each image has to be acompanied with several other text infos suplied by the uploading person. The image istself is stored in the filesystem and the data (like name of the user and imagefilename) are stored in a mysql myisam table. Now there are 2 problems I try to solve: o If more than one person is uploading images in the same time, it occures that the user name is missing. This info comes out of the db as well. I guess it is just not fast enough before it can be writen to the db again? oSome users would like to upload the image first and view it as a thumbnail. After this they would have to add the text data. I fear that some of them would not do this and I would have a file hanging around not belonging to anything. So I wonder if it would be possible to upload it first to a temp dir, add the data later and then move it from the temp dir to the propper one. I guess there has to be some kind of mechanism deleting old images periodicly which do not belong to anybody. I am kind of lost with this idea. Maybe some of you guys has a good idea on it?! Thank you for any help on this cases. Regards, Andy -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Erratic isset()
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... Hi Can anyone shed some light on this problem? The DB update only happens when I change the if(isset($submit)) to read if(!isset($submit)). Yes, I am using PHP 4.0.6 but have also tried with PHP 4.2.2, same problem. Code snippet: //HTML body ?php if(isset($Sumbit)): If this is a copy and paste, you have here $Sumbit which is not $submit and also not $Submit. If this is not your problem, try echoing the variable in question to ensure that it contains what you expect it to contain. /* Connecting, selecting database */ $link = mysql_connect(192.168.0.100, sff_user, sff98) or die(Could not connect); print Connected successfully.br; mysql_select_db(sff) or die(Could not select database); $doit1 = INSERT INTO members VALUES(NULL,'$first_name','$last_name','$addr1', '$addr2','$postnummer','$postort','$land','$tel','$mob','$email','$memb_date ','$comments'); mysql_query($doit1); //put the data in members table printf (bDatabase updated./b Enter a new member?); /* Closing connection */ mysql_close($link); endif; ? //print HTML form etc... Simon -- David Robley Temporary Kiwi! Quod subigo farinam -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] What's wrong with this code?
Hi all, I'm running PHP4. What's wrong with this code: ? $db = mysql_connect(localhost, Taj, wyethia); mysql_select_db(s2s,$db); mysql_query(INSERT INTO prod VALUES ( 'Name', 'ShortDesc', 'LongDesc', 'PriceOZ', 'PriceLB', 'URLOZ', 'URLLB', 'IMG') VALUES ('$_POST[Name]', '$_POST[ShortDesc]', '$_POST[LongDesc], '$POST[PriceOZ', '$_POST[PriceLB]', '$_POST[URLOZ]', '$_POST[URLLB], '$_POST[IMG]');) ? This will wrap, but, it should work. TIA, Taj -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] What's wrong with this code?
Hi all, I'm running PHP4. What's wrong with this code: ? $db = mysql_connect(localhost, Taj, passwordhere); mysql_select_db(s2s,$db); mysql_query(INSERT INTO prod VALUES ( 'Name', 'ShortDesc', 'LongDesc', 'PriceOZ', 'PriceLB', 'URLOZ', 'URLLB', 'IMG') VALUES ('$_POST[Name]', '$_POST[ShortDesc]', '$_POST[LongDesc], '$POST[PriceOZ', '$_POST[PriceLB]', '$_POST[URLOZ]', '$_POST[URLLB], '$_POST[IMG]');) ? This will wrap, but, it should work. TIA, Taj -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] What's wrong with this code?
I'd use var inclusions like this; VALUES (' . $_POST['Name'] . ', that might help you // -Original Message- // From: Shoulder to Shoulder Farm [mailto:[EMAIL PROTECTED]] // Sent: Monday, 2 September 2002 11:42 AM // To: PHP Database List // Subject: [PHP-DB] What's wrong with this code? // // // Hi all, I'm running PHP4. What's wrong with this code: // // ? // // $db = mysql_connect(localhost, Taj, passwordhere); // // mysql_select_db(s2s,$db); // // mysql_query(INSERT INTO prod VALUES ( 'Name', 'ShortDesc', // 'LongDesc', // 'PriceOZ', 'PriceLB', 'URLOZ', 'URLLB', 'IMG') VALUES // ('$_POST[Name]', // '$_POST[ShortDesc]', '$_POST[LongDesc], '$POST[PriceOZ', // '$_POST[PriceLB]', '$_POST[URLOZ]', '$_POST[URLLB], '$_POST[IMG]');) // // ? // // This will wrap, but, it should work. // // TIA, Taj // // // -- // PHP Database Mailing List (http://www.php.net/) // To unsubscribe, visit: http://www.php.net/unsub.php // -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] pg_fetch_result returns something other than boolean???
I am having trouble with the pg_fetch_result function when trying to access a boolean field in a PostgreSQL database. Here's the code snippet: $strField = blnAllDayEvent; $intFieldNum = pg_field_num($rsEvent,$strField); echo Field type for . $strField . is . pg_field_type($rsEvent,$intFieldNum); echo and the value is . pg_fetch_result($rsEvent,$i,$strField); if (pg_fetch_result($rsEvent,$i,$strField)) { echo or TRUE; } else { echo or FALSE; } echo br/; $strField = blnRecurringEvent; $intFieldNum = pg_field_num($rsEvent,$strField); echo Field type for . $strField . is . pg_field_type($rsEvent,$intFieldNum); echo and the value is . pg_fetch_result($rsEvent,$i,$strField); if (pg_fetch_result($rsEvent,$i,$strField)) { echo or TRUE; } else { echo or FALSE; } The displayed information is: Field type for blnAllDayEvent is bool and the value is f or TRUE Field type for blnRecurringEvent is bool and the value is t or TRUE Obviously, 'f' is NOT true. So, is this a bug or am I doing something wrong? I'm using PostgreSQL v7.2.1, PHP v4.2.1, on a FreeBSD 4.5-STABLE system. -matt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: What's wrong with this code?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... Hi all, I'm running PHP4. What's wrong with this code: ? $db = mysql_connect(localhost, Taj, passwordhere); mysql_select_db(s2s,$db); mysql_query(INSERT INTO prod VALUES ( 'Name', 'ShortDesc', 'LongDesc', 'PriceOZ', 'PriceLB', 'URLOZ', 'URLLB', 'IMG') VALUES ('$_POST[Name]', '$_POST[ShortDesc]', '$_POST[LongDesc], '$POST[PriceOZ', '$_POST[PriceLB]', '$_POST[URLOZ]', '$_POST[URLLB], '$_POST[IMG]');) ? This will wrap, but, it should work. TIA, Taj Well, hard to say as we don't have your db to run it against. You might try using mysql_error() immediately after the mysql_query to get an error message from mysql that will help you, or help us help you. -- David Robley Temporary Kiwi! Quod subigo farinam -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: What's wrong with this code?
Shoulder To Shoulder Farm wrote: mysql_query(INSERT INTO prod VALUES ( 'Name', 'ShortDesc', 'LongDesc', 'PriceOZ', 'PriceLB', 'URLOZ', 'URLLB', 'IMG') VALUES ('$_POST[Name]', '$_POST[ShortDesc]', '$_POST[LongDesc], '$POST[PriceOZ', '$_POST[PriceLB]', '$_POST[URLOZ]', '$_POST[URLLB], '$_POST[IMG]');) Maybe it's a typo but all you $_POST vars are wrong. They should be $_POST[var] not $_POST[var] as you have them. Jc -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php