Re: [PHP-DB] Re: Problem with mysql_fetch_array after first loop...
Steve McGill wrote: Jeffrey Baumgartner [EMAIL PROTECTED] schreef in bericht news:[EMAIL PROTECTED] I've made a little programme that deletes expired records from database tables. The troublesome bit looks like this... $query = SELECT ic FROM ic_ic WHERE date = CURDATE(); $result = mysql_query($query) or die(Unable to get old campaigns because . mysql_error()); while ($row = mysql_fetch_array($result)){ extract($row); ...delete records from tables where ic = ic are you by any chance doing a query inside this while loop? if you are then make sure you assign the result of the call to mysql_query() to a variable that is NOT called $result. } It works fine for the fitst value of $ic, but on the second time around I get an error message saying that line [starting with while...] is not a valid MySQL resource. This really puzzles me because it works one time around, but not after that. print_r(), var_dump() (and plain echo or print) are your friends: if you preceed the line starting 'while ($row =' with the following: var_dump( $result ); and then also add such a statement at the bottom of your while code ie: var_dump( $result ); while ($row = mysql_fetch_array($result)) { extract($row); // not a good idea IMHO // do your stuff var_dump( $result ); } then you should see it change on the second call to var_dump(), which will hopefully lead you to the code that changes the $result var when you don't want it to change. $ic, incidentally, is a string originally generated from the timestamp (ie. getdate[0]) - could this be causing a problem? Why don't you try it without using extract($row), and use $row[variable1] $row[variable2] instead in your loops. extract() pulls all the variables into the global namespace and can be quite dangerous as it might overwrite other variables. (this might be whats happening with the $result variable for example. also, how does extract() behave when trying to convert the [0] [1] [2] variables? you might be better off using mysql_fetch_assoc() ditto, dont extract() in this situation - its a waste of a function call and a waste of variable initialization... just use the values in the $row array directly... e.g. echo $row['ic']; // this could have been $ic if you had called extract($row) Best wishes, Steve -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] suggestions
Mignon Hunter wrote: Hello Mignon, this is really a php-generals question me thinks (you don't even mention a DB ;-), regardless I need to dev a small app and I can think of a couple different ways to handle it but not sure the best way. I need to register those who come to our site that want to download .pdf's. They will fill out some information before I redirect to the pdf. I'm thinking the best way to handle this is sessions, but is it appropriate to store all of the users info - so that if he downloads 2 items - I can re-populate the fields so he doesnt have to? So if they click on an additional pdf I'll need to somehow check for the session and re-populate 11 fields, and they will only have to fill in one field at that time. Or would cookies be better ? I need to store probably 11 different form variables. Also - would you store the variables in an array in the session? This seems neat and tidy... lets see: if you put the data in a cookie then you are allowing malicious users to change that data after you have stored it (so you will have to check it _everytime_ you want to use it)... best to stick an array in the $_SESSION array.. that way you oly need you sanitize the data when you add/change it - there is no problem with storing an array with 11 items it in in the session, and using an array rather than 'loose' variables would definitely be neater - you have all the user/pdf data in on place and its easy to extend that ammount of info you store (i.e. if your client decides users must fill out more information to download a pdf) Hope this is clear. Any advice/guidance/sample scripts would be appreciated. Thanks -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] suggestions
Mignon Hunter wrote: Sorry - forgot to mention the data I'm collecting will go into a dbase, that's why I posted here. fine. but your not having trouble putting data into a DB. yet. :-) Thanks I'll work with the session angle. Please see if this logic is flawed... The hyperlink to the pdf will spawn a new window with my form to fill out. So I think I must start the session in the first page, the one that the pdf is on. start the session on _every_ page. its best to put all the session startup code in one file and include that on each page (thats the general principal anyhow). So I assign the variables collected in the 2nd window the session of the first. Then when the 2nd window is closed store in session and write to dbase ? the session (or the server for that matter) does not know anything about windows. you can use 100 windows or just one, makes no difference. Upon closing the 2nd window redirect to the pdf. If user wants another file, spawn a third window with form but fill in most of what he entered (ie name,address,etc). I get this from the current session right? 1. user clicks link to download pdf. 2. server send a page with a form in it. (possibly partially filled in from previous download in this session) 3. user submits (properly filled in) form. 4. server santizises user input, stores/updates session info, adds record to DB, then: either: spits out a PDF with appropriate headers so that the browser presents a download dialog. or: redirect to a page with a link (with some kind of token/key in the query part of the URL) to a page that spits out a PDF. or: redirect to a page with some javascript that sets the location of the parent window to a new URL or: something :-) whether you use multiple windows to accomplish this on the clientside is irrelevant to what you have to do on the server. if you are redirecting you will probably want to pass some token that you can check (a token is only generated if someone filled out a form) before outputting the PDF. Ultimately the data in the dbase is the goal and I just dont want the user to have to re-enter you do realise that if you redirect, after the user submits, to a url like: http://yourserver.com/yourpdf.pdf then I can skip the whole filling the form business in and just grab the file directly? Thanks Mignon ... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] error handling in query execution
Chenri wrote: i have a script that update records with this construct: while( ){ query_string='UPDATE ...'; updateRecord(query_string); } the problem is when there are wrong query_string (such as incorect syntax) can i make sure that the other query, the next one after the wrong query still goes. I've read about the @ operand but i still doesn't understand does the script stop when the error occured or does it still continue the process Cherni, your updateRecord() function must handle the query error thats all. the '@' sign is there to repress errors so that they don't show up on screen or in your log. you may need to use the '@' to stop a warning from being emitted when you pass a bad query (you don't say which DB you use and I haven't used mysql in a long time) whether or not the script stops depends on what kind of error occurs. FATAL errors are exactly that, WARNINGs don't always need to be a show stopper it depends on your error checking/handling. to be honest though if you are buidling the SQL string then there is no reason for the SQL to be invalid. just make sure to check and sanitize all the variables you wan't to place inside the query (e.g. searching for name or selecting on id, etc) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] GD2 library
Balwant Singh wrote: Sorry I am asking a question which is not directly linked to this forum but i am confident that many of you have the answer for it. is it that much trouble to ask you question in the 'correct forum', there is the php-generals list next door where this question fits perfectly. i am using PHP 4.2.2 with GD 1.63. now i want to upgrade the GD1.63 to GD2. i have installed the GD2 in my system but still my system is showing GD 1.63. May pls. advise me what needs to be in php.ini file or anywhere so that my php read the GD2. have you restarted apache? with best wishes balwant -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP and JOIN... (I know.. it's easy!)
[EMAIL PROTECTED] wrote: Hi all, long time no post... I've rebuilt a download tracking system my company uses. I built the original, and thought that a restructure would be a doddle! Ooops! ;-) Anyhoo... I used to capture each download in it's own row, replicating user data each time. (Eg: if a user downloaded 5 files, I'd capture their address, email etc, 5 times) For the redesign, I've got several tables. a file list table, a user list table, and a capture list table. I'm built 90% of the front end, and it works great! However, I'm having trouble getting my head round the reporting side of things. (probably need to stop thinking about it for a while, but I don't have that luxury) My admin users, will come in, and select a file ID to view who's downloaded it. So with a file ID No, I need to also get the following: 1. Get the file info from the file table 2. go to the captures table, get all the fields where the file id is the same as theonce requested the admin user can specify multiple files simultaneously to inspect? 3. count each user that has downloaded it 4. get thier data from the users table Now I could do this with 4 seperate queries, and a few for loops etc... But I'm trying to figure out JOIN... as I'm told I can do it all in one query, and make a temp fake table? can't see why you need a temp table at this junture - maybe you could explain _exactly_ what you want to report to the user (and not so much how/where you intend to get the data from) I've googled for a decent tutorial, but perhaps I'm just panicing, but they all seem over my head... (My flatmate is a PHP developer too, and she says that it's easy!.. so I six women in the world that grok php... and you live with one, b'std :-) hope I'm just stressed) Anyhoo, does anyone know of a decent site, that'll really dumb it down for me, or could talk me through what I'm after? wha you want more??? the female flatmate who groks php is not enough :-) only kidding. Sorry for the long winded E-mail.. but I'm pulling my hair out here.. :-( post your table structures. that way we can see which fields to join on... btw this is a pure SQL problem - no php knowledge technically require, not to worry! Tris... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP and JOIN... (I know.. it's easy!)
[EMAIL PROTECTED] wrote: Cool. cheers for the quick responce... Well, my flatmate is one of two, I live with a lesbian couple in London... One is a falsh guru, sho recently got into PHP (she's a REAL brain box, and picsk stuff up sooo much quick than us mere mortals!) Hard life init ;-) shucks. :-) Anyhoo, my prob, in more detail, with table structures (at the bottom!)... An admin user should be able to: Select one (or more, though I'm fine with looping, once I get this first one done) file ID number to see who's downloaded it, and see detailed info on them. So I'm listing a list of all file id No's on page 1. when the user selects the ID they wanna report on, the MYSQL query should read something like: 1. Get, and count user_id from table captures. 2. get all user info from table users, based on above user_id. I'll then make a page that looks like this: file name: User(s) 12.doc [EMAIL PROTECTED] (12 times) [EMAIL PROTECTED] (1 times) [EMAIL PROTECTED] (2 times) etc.. I'll make the email addresses/file name links to detailed info, but I'm fine with doing that... Once I see a few Joins in action based on what I'm trying to do, I'll get it.. I'm self taught (as most of us are right?) and learn better from real :-) life example than books... some books are worth their weight in gold. some not. Please find my table structure below... very good :-). I so *(*^* busy that I haven't got time to get my head into mySQL mode. so to other listers with some JOIN foo: I've extracted sufficient info from the OP, any care to finalize? :-) (sorry tristan) === // stores only file id, user id and date etc... CREATE TABLE `captures` ( `id` int(11) NOT NULL auto_increment, `user_id` int(11) NOT NULL default '0', `date` date NOT NULL default '-00-00', `file_id` int(8) NOT NULL default '0', `page_id` int(11) NOT NULL default '0', `ip` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ; // all data pertainign to the file CREATE TABLE `files` ( `file_master_bu` varchar(255) NOT NULL default '', `id` int(8) NOT NULL auto_increment, `uploaded_by` varchar(255) NOT NULL default '', `uploaded_date` date NOT NULL default '-00-00', `edited_by` varchar(255) NOT NULL default '', `edited_date` date NOT NULL default '-00-00', `file_title` varchar(255) NOT NULL default '', `file_name` varchar(255) NOT NULL default '', `file_cat` varchar(255) NOT NULL default '', `file_type` varchar(255) NOT NULL default '', `file_desc` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ; // the users who fill out forms, are put here. I do a search each download to see if they're in the database already, based on email address... but that's kinda irrelevent here... ;-) CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `salutation` varchar(255) NOT NULL default '', `forename` varchar(255) NOT NULL default '', `surname` varchar(255) NOT NULL default '', `email` varchar(255) NOT NULL default '', `tel` varchar(255) NOT NULL default '', `fax` varchar(255) NOT NULL default '', `company` varchar(255) NOT NULL default '', `job_title` varchar(255) NOT NULL default '', `street` varchar(255) NOT NULL default '', `street2` varchar(255) NOT NULL default '', `city` varchar(255) NOT NULL default '', `zip` varchar(255) NOT NULL default '', `state` varchar(255) NOT NULL default '', `country` varchar(255) NOT NULL default '', `hear` varchar(255) NOT NULL default '', `us_opt` varchar(255) NOT NULL default '', `eu_opt` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ; | -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Random Password problem
J. Connolly wrote: I am using this php in order to create, store and send random passwords to people who want to join my mailing list. ?php function random_password () { $seed = (integer) md5(microtime()); mt_srand($seed); your seeding the randomizer with the value zero each time! the expression: (integer) md5(microtime()) is (almost) always going to equal zero (unless it happens to start with one or more numeric chars). basically get rid of the code that seeds the randomizer, unless your using a really old version of php, because you don't need to seed the randomizer at all. if you remove the line: mt_srand($seed); your passwords will drastically increase in 'randomness' $password = mt_rand(1,); $password = substr(md5($password), 3,9); return $password; } ? ?php $msg = random_password(); echo $msg; ? I seem to be getting the same number very often which makes me fear that fear causes hesitation, hestitation causes your worse fears to come true. (yadda yadda, that film is sooo pre-Matrix ;-) this is not so random. I am a noob so I do not know if this is coincidence or a fault in my coding. Right now, I have been setting up passwords manually, but would like users to be as free from me as possible. Any direction would be helpful. BTW, I keep getting the following number an absurd amount of times. I have deleted cookies and even gone to other machines, and yet it still generates this number. 8f31a3 Thank you, jozef -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Forms...
Bastien Koert wrote: I use this format input name=right_eye type=checkbox value=1 ? if ($rows['right_eye']==1) { echo CHECKED ; } ?nbsp;Right Eye(s) if your into XHTML: input name=right_eye type=checkbox value=1 checked=checked value=1 / (Bastien already showed how to dynamically determine whether the chkbox is checked :-) ... all attribs in lower case, and every one must have a value set, in the case of the 'checked' attrib the value is 'checked'. I haven't tried it out but I assume the following html would result in an unchecked box - I also imagine that that may depend on the DOCTYPE of the output page - and I may just be plain wrong :). input name=right_eye type=checkbox value=1 checked= value=1 / Bastien From: Mark Benson [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Forms... Date: Wed, 9 Mar 2005 19:12:31 + Does anyone know if it is possible to have 'checkbox' elements in a form appear 'checked' or 'unchecked' when a page loads data from a MySQL data source? Can I use an attribute in the input tag to switch that? -- Mark Benson AIM - SilValleyPirate MSN - [EMAIL PROTECTED] Visit FlatPackMacs online: http://fpm.68kmac.com Visit my Homepage: http://homepage.mac.com/markbenson Introducing Macintosh Classic II - pick one out on your way past the trash! -- 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] Merge result set of query?
Martin Norland wrote: ioannes wrote: My first attempt was to use $result=array_merge($result1,$result2) - doesn't work. 'not a valid resource' I have two databases with different connections, so MySQL UNION query would not work. How do I merge the result set of the queries in that case? You're going to have to merge the results within PHP. not a valid resource is an error you get when you try to read from a result set and what you pass it isn't a resource for a result set. I think you're doing something along the lines of: $result1 = query_database_one($somequery); $result2 = query_database_two($someotherquery); $result = array_merge($result1, $result2); while (mysql_fetch_row($result)) { while reading I thought, would this: while (($row = mysql_fetch_row($result)) || ($row = mysql_fetch_row($result2))) { // just do it. } .. work (due to shortcircuiting)? and how ugly is it? // foo } ... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] insertion problem (2)
Stephen Johnson wrote: This may not necessarily be the problem. But I am not sure that you should be capitalizing the first character of your variable. That is a special type of PHP variable - which I do not use normally - so I can not remember what it is called. However, put all your variables to lower case except the pre-defined variables such as $_POST and $_GET etc. See if that helps good on ya for trying to extract the question/problem from this guy Stephen! I just wanted to add that variable names can be in any case, may not start with a number (may contain alpha-numeric chars) and are case-sensitive. the following are all valid (and different): $Tee1 = 1; $tee1 = 1; $_tee1 = 1; $_TEE1 = 1; $Tee= 1; ?php /* Stephen Johnson c | eh The Lone Coder http://www.thelonecoder.com [EMAIL PROTECTED] 562.924.4454 (office) 562.924.4075 (fax) continuing the struggle against bad code */ ? From: sultan Ibraheem [EMAIL PROTECTED] Date: Wed, 9 Mar 2005 14:50:57 -0800 (PST) To: [EMAIL PROTECTED], php-db@lists.php.net Subject: [PHP-DB] insertion problem (2) Thanks for your time,, This is the code: $uu=mysql_query(insert into voters2 ('id','username','constnum','name','fname','gname','lname')values('$T10','$T1' ,'$T11','$T4,'$T5','$T6','$T7')); $uu2=mysql_query(insert into voters2 ('sex','birth_day','email','password') values('$D1','$T9','$T8','$T2')); - Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Merge result set of query?
Martin Norland wrote: Jochem Maas wrote: Martin Norland wrote: while (($row = mysql_fetch_row($result)) || ($row = mysql_fetch_row($result2))) { // just do it. } .. work (due to shortcircuiting)? and how ugly is it? // foo } That would work if you just wanted to iterate over both resultsets and do the same thing, yes. Say, if you had lists of users who signed up for something in two separate databases, you could print them all out with that. Since he said union and not join - that is probably his intention. that was what I had in mind when it popped into my head :-) I can't decide if that code is beautiful or horribly ugly though... I would have to say it's beautiful so long as the 'just do it' is very short - if the 'just do it' should be a function - then you should just suck it up and do two while's. Also, for every result in $result2, you have to poke at the first database and say any more yet?, which is hackish. slick 'obfuscated perl' entry type fix though :) [okay, it's not obfuscated in the traditional sense] ok, I apprieciate your comments - its always good to get a experienced 'hackers' view on things. thank you Martin! cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Forms...
Neil Smith [MVP, Digital media] wrote: At 07:52 10/03/2005 +, you wrote: Message-ID: [EMAIL PROTECTED] Date: Wed, 09 Mar 2005 20:37:36 +0100 From: Jochem Maas [EMAIL PROTECTED] if your into XHTML: input name=right_eye type=checkbox value=1 checked=checked value=1 / Actually that's invalid XHTML (it won't validate) due to a typo I guess. true, yeah I added an extra value attr. wasn't paying enought attention. Each XML (aka XHTML) DOM element can only have a ~single~ attribute with a particular name. The typo above has two copies if the 'value' attribute which would prevent the XHTML being valid XML. HTH Cheers - Neil -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Log in multiple users to MySql
Mahmoud Badreddine wrote: I authenticate users of my database with the Apache dialog box. I would like to know where do these values (usernames and passwords) get stored so that I can use this information to log in to the MySql database. its not a DB related question, you should have posted at php-generals, well actually you should have STFW but anyway the following should tell you what you need to know: $login = isset($_SERVER[ 'PHP_AUTH_USER' ]) ? $_SERVER[ 'PHP_AUTH_USER' ]: false; $pass = isset($_SERVER[ 'PHP_AUTH_PW' ]) ? $_SERVER[ 'PHP_AUTH_PW' ]: false; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How to programmatically finding freetds.conf location?
Ashwari Nugraha wrote: Thanks Joseph, I understood about your idea. But it can be more than one freetds.conf found, all I need is finding ones which is used by mssql_connect(). Some people do not delete FreeTDS installation source that is still contain that file. if you know that then you know the structure of the source tree, filter out freetds.conf files found with a 'source tree' subpath. could be a way to do it... I know nothing about freeTDS, I wouldn't talk to an MSSQL server if it paid me. :-) I had to look up freeTDS and I found out what it was... some more clicking got me to this page: http://www.freetds.org/userguide/freetdsconf.htm#FREETDSCONFLOCATION which is probably a good place to start investigating your options. (maybe you have seen it already?) Joseph Crawford wrote: you could execute the exec command in php and run a locate freetds.conf or whereis freetds.conf or find freetds.conf, i believe whereis only locates binary files not sure though. read up on exec here http://us2.php.net/manual/en/function.exec.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] ways of making access and visib compat with 4 and 5
tony yau wrote: hi all, I'm trying to make my classes compat with php4 and php5 is there a way of doing something like this: if( version== 4) define( VISIBILITY, ); else if (version==5) define( VISIBILITY, protected ); class Flex { VISIBILITY function CompatFunc(); } this will never work. the if/else block is run _after_ the code is compiled. the line 'VISIBILITY function CompatFunc();' will always fail because php won't recognise the token 'VISIBILITY'. not that putting a constant where you do (even if it were defined) would work anyway. btw: you could/should have asked this question on php-generals (there's no reference to DB usage/problems in your question) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Queries close session
Adept-Hosting.Net Administration wrote: I am using the following script to maintain a login session on some pages: ?php session_start(); if(empty($_SESSION['username'])) { die('An error has ocurred. It may be that you have not logged in, or that your session has expired. Please try a href=index.phplogging in/a again or contact the a href=mailto:[EMAIL PROTECTED]system administrator/a'); } ? The sessions are stable and work fine EXCEPT when I run another PHP script on the web page such as: the script below does not call session_start()- you must call session_start() on each request that you need the session data, normally people put all their session check/start-up stuff in a seperate file and then include that when needed: ? require db_connect.inc; require session.inc; // do you queries and output the results etc! ?php // Make a MySQL Connection require db_connect.inc; // Retrieve all the data from the example table $result = mysql_query(SELECT * FROM members WHERE Status='Inactive') or die(mysql_error()); echo table border='1' cellpadding='0' cellspacing='1' align='center'; echo tr thCertificate #/ththDan rank/ththFirst Name/th thLast Name/th /tr; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo trtd; echo $row['Cert_number']; echo /tdtd; echo $row['Dan_rank']; echo /tdtd; echo $row['First']; echo /tdtd; echo $row['Last']; echo /td/tr; } echo /table; ? I'm assuming that I am either not maintaining the session properly or not linking the scripts to the session. Any pointers on how to accomplish what I'm trying to do? Thanks, - Ken -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Transaction over persistent connection problem
Manuel Lemos wrote: Hello, on 04/27/2005 11:49 AM Oskar said the following: Ok. So the idea of splitting one transaction into two steps of a script is wrong? Yes, it is not possible to achive that. What happens is that first access to script is handled by one Web server process or thread and you cannot assure that the second access will be handled by the same Web process or server to finish the same transaction that was started. some thoughts: if he ran the the page/script on a seperate webserver (configured to run one process), especially for this one task - to which only one person [c|w]ould connect - then it would be technically doable no? Furthermore, you should never leave a transaction open that you cannot guarantee that it will finished in a very short notice, otherwise it may say database server is in the US, and connecting server (that makes use of transactions) is in Europe... how are you going to guarantee that the connecting server will never suffer network or power loss midway thru a transaction? (I'd put money on the fact that the same thing has crossed the minds of more than one database engine developer.) block the access to the whole database forever. thats a broad statement. a transaction doesn't have to block access per definition, and its not unfeasable to suggest that some database engines may account for the possibility for 'hung' transaction in some kind of garbage collection routine...? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Letters loop
MIGUEL ANTONIO GUIRAO AGUILAR wrote: Hi!! I wanna a do a for loop with letters, Is this possible? for ($i = 'A'; $i = 'Z'; $i++){ // code } try it. php -r ' for ($i = a; $i z; $i++){ echo $i,.; } echo z;' -- MIGUEL GUIRAO AGUILERA Logistica R8 - Telcel Tel: (999) 960.7994 Cel: 9931-6 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] how do i fetch some text
chintan wrote: how do i fetch some text from a webpage for some generated field? like i want to fetch a score line from a sport site in which the line says score? actually i want to fetch an IP from my ISP's page which displays it with my user name. where is the DB in this question? (probably you would get better response on the php-generals list.) what you want to do sounds quite involved, if you want your script to grab the same page as you see in your browser then you will probably have to use something like the cURL extension or use a shell cmd like 'wget' in order that you can spoof UserAgent headers, pass login info, send a valid cookie along with the request. once you have the page you will have use some code to 'scrape' out the data you want, a suitable regular expression is the first thing that springs to mind inconjunction with preg_match() - but there are lots of other ways, php is abounds with string searching and manipulation function (time to dig into the manual :-) you might also want to search for the term 'screen scraping' or variations in order to get a better understanding of how to go about it. maybe there is a much easier way to do what you want. in order to find out answer the following 2 questions, maybe it will help someone to offer a totally different solution: 1. what is the relevance of the IP address, to what does it belong? 2. why do you need this IP? what is your end goal? rgds, Jochem -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Long running db queries and the STOP button
Bastien Koert wrote: Few things I can think of: 1. warn the user that the query may take some time and then show a splash type screen that indicates that something is happening 2. Run the whole thing in a new window without the toolbar 3. rework the query so it doesn't take so much time. If there are a lot of joins in the query, you need to re-order the joins to make the combinations more efficient, perhaps break up the queries and place the individual results in array. Then manipulate the arrays to show the data how you want. (I did this to great effect to get a 4 minute query down to 10 seconds) I just had the idea (never tried it myself) that you could possibly fork the request process and let the child process perform the query and the let the parent process (to which the browser 'is connected') wait around for the child to finish ... outputting any results, it could then be possible for user abort to be trapped in the parent and them have some code that kills the child process (or possibly that apache/php responds immeditately in the parent and just lets the child keep running - or kills it off internally) hope that makes sense. it does to me, but maybe I didn't explain it well. Bastien From: [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Long running db queries and the STOP button Date: Thu, 27 Oct 2005 16:03:58 +0200 Hello list, We are working on a project where we use PHP5 inside Apache2 and run very long running queries on mysql 5 and postgresql. A single query might run up to several minutes, and generally uses 100% CPU on the database server. So far everything is fine. Now what happens, is that sometimes the user hits the stop / back button before the query completes and reissues a new one. The result is that two queries are running on the database server, even though the results of the first query will never be used. Furthermore as both queries are concurring for the CPU, the second query takes much longer than normal. PHP will only realize that the connection was closed by the browser once the database query is completed, but not during the query itself. What we are looking for is a way to cancel a running query immediately when the user hits the back / stop button on his browser. We found no real solution for this problem in the usual places. Any ideas, thoughts or comments are very welcome! Cheers, Thomas - Thomas Seiler Ing. sys. com. dipl. EPFL SWISSCOM AG Innovations Security and Service Management Ostermundigenstrasse 93 CH - 3050 Bern SWITZERLAND Phone: +41 (0)31 342 42 69 Mobile: +41 (0)79 427 97 26 Fax:+41 (0)31 892 62 27 [EMAIL PROTECTED] http://www.swisscom.com -- 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] Long running db queries and the STOP button
[EMAIL PROTECTED] wrote: Hi Jochem, Thanks for replying I just had the idea (never tried it myself) that you could possibly fork the request process and let the child process perform the query It makes perfectly sense to us, but it seems it is only possible to fork (pcntl_fork) with php running as CGI :( oops missed that bit in the manual... still ... if you are using apache then virtual() might offer a solution? (just guessing) otherwise you might look into writing a little deamon (i.e. a webservice that only your pages anbd/or scripts can access) which handles running the queries can be polled as to the status of a query and its result (if finished) .. such a deamon would be CLI based and could use process forking to handle multiple requests to run long queries rather than use the img src=monitorscript.php trick you might want to look into 'AJAX' on the client side (to do the polling, start the query, etc) in order to have more control/information on that end. From php.net: snip arnold at helderhosting dot nl 13-Feb-2005 10:12 It is not possible to use the function 'pcntl_fork' when PHP is used as Apache module. You can only use pcntl_fork in CGI mode or from command-line. Using this function will result in: 'Fatal error: Call to undefined function: pcntl_fork()' snip This somehow makes sense, because one would fork the entire apache process, Including all the signal handlers, open file handles for log-files and so on... Furthermore fork is only supported on linux/*nix but not in the windows world, and it has to be enabled at configure time. We have so far tried to use javascript to detect when a windows is closed and send a second HTTP request to kill the database thread. This however does not work reliably, because javascript has no event for the Stop button of the browser :( a daily annoyance. just like its impossible to trap when the window is actually closed (as opposed to the document merely unloading) The next idea is to include a img src=monitorscript.php in output generated by the query script. This should open a second HTTP connection to the monitor script on most recent browsers. In this script we can check connection_aborted() and sleep(1) in a while loop without sending any output. If the connection was aborted, we can kill the corresponding db thread. The remaining problem with that solution is that we also have to detect when the db query script has terminated and then exit the monitor script. Otherwise the browser keeps loading that monitorscript and never finishes. This solution has two drawbacks, it work over a http proxy (these tend to finish queries in order to cache the content) and it works only when the browser is doing several queries in parallel. Cheers, Thomas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Long running db queries and the STOP button
[EMAIL PROTECTED] wrote: Hi Jochem, if you are using apache then virtual() might offer a solution? (just guessing) Cool, I didn't know of that one. But it seems that is just calls back into apache, i.e. it doesn't generate a second independent thread. This would have been too good to be true :) php engine is thread safe (in principal?) but chances are very high you run extensions that are not. in short running php in a [true] threaded server is only for those who enjoy a good root canal. We have since found a solution for postgres. It supports asynchronous queries and also killing of them: nice feature. //snip -- // Setup query cancel handler ignore_user_abort(false); register_shutdown_function(cancel_query); ... // Handler function cancel_query() { pg_cancel_query($dblink); } ... // Actual Query pg_send_query($dblink, $query); // this is non-blocking // This seems to be needed so that php recognizes closed connections while(pg_connection_busy($dblink)){ usleep(50); echo ' '; flush(); } // get the result from async query execution. $result = pg_get_result($dblink); //snip We are now looking for something similar for mysql. Cheers, Thomas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php