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
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
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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] php5-sessions next
mel list_php wrote: Dear Martin, Thank you very much for that, I made the suggested changes. The problem was again coming from the session.save_path directive which was not well configured. With your settings I know have a wonderful display of undefined index, coming from all that non instantiated variables...at least I know what I have to do now!! you have 3 options with these kinds of errors: 1. change error_reporting to not include NOTICEs 2. change all the relevant code so that all vars are initialized (possibly lots of work) 3. use the '@' sign on the vars to repress the errors e.g: if (@$_GET['rule']) { // take over world } I wouldn't recommend 3 unless its a specific case and you know what you're doing One thing: I use @session_start() because in the other case I have a warning a session has already been started. On the other had have to call it at the beginning of each script. Is there a way to test that? you may be able to get away with testing to see whether session_id() returns an empty string or not (i.e. if its empty you still have to start the session) although I would recommend rewriting your session starting code so that you only call session_start() in one place - if you put all this code in a seperate file you can then require_once() the file as and when you need it. With php5 I also saw than a script having a white line and only later on the ?php is not interpreted but displayed as text. Any reason for that? that doesn't sound like it should be happening - post some code please. Once again thank you for your help, and sorry I should have displayed the errors at the beginning. now you know :-) - the next time someone hits the list with a similar case you can 'parrot' Martin's tips! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Expiry Date ($date function)
Ron Piggott wrote: That strtotime is a neat little command. With a bit more searching I found that this works: $expiry_date = strtotime(+21 days); $expiry_date = date('Y-m-d', $expiry_date); echo $expiry_date; The computer couldn't cope with me doing it in just one line --- I got a parse error. the computer coped when I did it on oneline, maybe you had a typo or something: echo date(Y-m-d, strtotime(+21 days)); sidenote: I use doublequotes here because its easier when testing in a linux shellbut unless you need string interpolation its better to use single quotes for your strings. Ron - Original Message - From: Calvin Lough [EMAIL PROTECTED] To: Ron Piggott [EMAIL PROTECTED]; PHP DB php-db@lists.php.net Sent: Wednesday, March 02, 2005 10:50 AM Subject: Re: [PHP-DB] Expiry Date ($date function) The strtotime function should work the best. $add_twentyone = strtotime(+21 days); I dont know if that will work or not. I just found that method in the php doc and it looked interesting. Hopefully it will work for you. Calvin On Wed, 2 Mar 2005 04:41:04 -0500, Ron Piggott [EMAIL PROTECTED] wrote: I figured out that the syntax below creates the date in the way it may be stored in a mySQL table: $todays_date=DATE('Y-m-d'); Is there any way to add 21 days to this as an expiry date? For example if the date was March 20th 2005 21 days would be in April --- is there any way of dealing with this? Ron -- 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] 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] Notice: Undefined index: op
Martin Norland wrote: J. Connolly wrote: ... You may want to use a different quoting style - I can't recall the name, but it's taken from perl HEREDOC. (i believe its custom to write it in capitals,) echo EOF form action=$_SERVER[PHP_SELF] method=POST ... the rest of your stuff, then on its own line right at the beginning of the line (no tabs/etc. :( ) ... EOF; it basically echo's until it sees that delimiter, that could be EOD or STOP or whatever (well, there might be reserved words issues - I could more easily check if I could remember the name of the quoting style...) Cheers -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] JOIN problem
Zouari Fourat wrote: am using mysql 3 so i can't do that subquery, how can we do that in mysql 3 ? and neither can anyone else ;-)... rather a pain, but mysql.com have been kind enough to give a detailed explaination on how to rewrite subselect queries as join queries: If you put your brain in gear this page should tell what you need to know: http://dev.mysql.com/doc/mysql/en/rewriting-subqueries.html If you get stuck, you know where the list is :-) On Mon, 7 Feb 2005 19:47:08 +, Simon Rees [EMAIL PROTECTED] wrote: On Monday 07 February 2005 18:22, Zouari Fourat wrote: Hello I have 2 tables with two columns in each one (cloned tables) like this : ID int(6) UserName varchar(25) and i would like to select usernames from table1 that doesnt appear in table2 so i did this : Depending on which database you're using you may be able to do this: SELECT a.username FROM table1 a WHERE a.username NOT IN ( SELECT b.username FROM table2 b ) cheers Simon -- ~~ Simon Rees | [EMAIL PROTECTED] | ORA-03113: end-of-file on communication channel ~~ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] insert (database)
Martin Norland wrote: Jochem Maas wrote: Yemi Obembe wrote: the objective of the script below is to first search if a subscriber is already in a list before subscribing his email (so as to prevent double subscription). the select part works finebut the insert doesnt. know why? if ($v = strtolower($_POST['email'])) { what happens when $_POST['email'] is equal to 'script document.location = http://www.evilkid.net/?stolencookie+document.cookie; /script'; or something like that? Just something to think about. Then the malicious user gets to send their own cookies for this site to another site of their choosing :P. I would be more worried about it being equal to things like: Spam my Enemy [EMAIL PROTECTED] + Spam my Enemy also [EMAIL PROTECTED] + etc. or \r\nFrom: Idiots Inc. [EMAIL PROTECTED] or '; Delete from arbitrary_table_name where 'yes'='yes ah yes - that would an effective attack in/on an email ;-) All of which are easily prevented with some attention to detail. (or in some cases newer versions of software, which explicitly allow only one statement per call). Finally - the concept of bind variables (or equivalent) are your friend (as Jochem already knows with firebird iirc). yes indeed! praise to the guy who wrote the new firebird extension :-), savin' my ass on a daily basis :-) Cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Form Mail Script/ Class
Malcolm JC Clark wrote: I am looking for a good reliable php script/ class to process enquiries. Maybe there is a de facto php script/ class like Matts perl Script Archive? try phpmailer: phpmailer.sourceforge.net Kind Rgds Malcolm -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP5 classes mysql bug ?
Viacheslav Kaloshin wrote: Here is testcase PHP 5.0.3 (cli) (built: Dec 17 2004 10:47:41) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies ?php class MySQL { private $mysql_link=0; private $mysql_result=0; function __construct() { $host=localhost; $basename=test; $username=test; $userpassword=; $link=mysql_pconnect($host,$username,$userpassword); if($link) { mysql_select_db($link); $this-$mysql_link=$link; your syntax is wrong in the line above (and elsewhere), it should be: $this-mysql_link=$link; echo At constructor: ; echo $this-$mysql_link; echo \n; return 0; } else { return 1; } } function __destruct() { echo At destructor ; echo $this-$mysql_link; echo \n; if($this-$mysql_link) { mysql_close($this-$mysql_link); } } function query($query_string) { echo before query: ; echo $this-$mysql_link; echo \n; $this-$mysql_result=mysql_query($query_string); // can change to this #$this-$mysql_result=mysql_query($query_string, $this-$mysql_link); echo after query: ; echo $this-$mysql_link; echo \n; if($this-$mysql_result) { return 0; } else { return 1; } } function result() { return mysql_num_rows($this-$mysql_result); } function fetch() { return mysql_fetch_array($this-$mysql_result, MYSQL_NUM); } function clear() { return mysql_free_result($this-$mysql_result); } } $m= new MySQL(); $m-query(select 1+2); $res=$m-result(); $res=$m-fetch(); $m-clear(); $m-query(select 2+3); $res=$m-result(); $res=$m-fetch(); $m-clear(); ? this script output should shwo the same id. but in my case i see next lines: At constructor: Resource id #4 before query: Resource id #4 after query: Resource id #5 before query: Resource id #5 after query: Resource id #6 At destructor Resource id #6 What i am not understand? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] insert (database)
Yemi Obembe wrote: the objective of the script below is to first search if a subscriber is already in a list before subscribing his email (so as to prevent double subscription). the select part works finebut the insert doesnt. know why? if ($v = strtolower($_POST['email'])) { what happens when $_POST['email'] is equal to 'script document.location = http://www.evilkid.net/?stolencookie+document.cookie; /script'; or something like that? Just something to think about. $db = mysql_connect(mysql, usser, pw); $con = mysql_select_db(ng,$db); $sql = SELECT * FROM mytable WHERE email='$v'; $res = mysql_query( $sql ) ; if ($row = mysql_fetch_array($res)) { echo bYour email: u$v/u already in the listbr; } else { $sql_in = INSERT INTO arcadia ('email') VALUES ('$v'); $result_in = mysql_query($sql_in); echo bYour email: u$v/u subscribed!br; you use different table names in each query. is that the intention? } } else { include(index.php); exit; } - A passion till tomorrow, Opeyemi Obembe | ng.clawz.com - Do you Yahoo!? Yahoo! Search presents - Jib Jab's 'Second Term' -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Developer needed in London
Underodog H.R. wrote: Sorry for using the list in this way, wont happen again. wtf. 'they' posted it twice with the same message... thats the definition of 'again'. the fact that 'they' can't even spell their company name correctly would make me think twice about working there ;-) Underodog H.R. [EMAIL PROTECTED] ^ !!! And why is a degree so important if 'all' they want if a monkey who can do D/HTML, PHP MySQL - these are the easiest IT wotsits on the planet, ok playing minesweeper is easier :-). I mean easy as in accessible not easy as in 'no hard work or study needed' anyone can go to the local college and train to be an electrician but you need a degree to write php code?? --- nuff of that, I've had too much coffee and too many traffic jams this morning. PLEASE DON¹T REPLY TO THIS MESSAGE THROUGH THE LIST RESPOND DIRECT TO [EMAIL PROTECTED] Job Opportunity: Web Developer/Designer In-house in London (not outsourced). A great opportunity to join a young vibrant company working on exciting high profile projects. Would suit recent graduates and experienced pro's alike. A strong background in web technologies and programming is essential, good working knowledge of; D/HTML, PHP, MySQL is necessary, other technologies (Flash etc) are a bonus. Please apply by sending your CV to [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP] Re: [PHP-DB] Developer needed in London
Jochem Maas wrote: Underodog H.R. wrote: Sorry for using the list in this way, wont happen again. wtf. 'they' posted it twice with the same message... thats the definition of 'again'. I just noticed that they crossposted rather than post twice. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: [PHP] Re: [PHP-DB] Developer needed in London
Martin Norland wrote: Jochem Maas wrote: Jochem Maas wrote: Underodog H.R. wrote: Sorry for using the list in this way, wont happen again. I just noticed that they crossposted rather than post twice. That's three times now I've seen the statement that it won't happen again! Unforgivable! Seriously though - their name is set to Underodog - that *is* pretty damned bad. Unless they're manually tweaking the From: field everytime they send mail from jobs@ - in which case, woops. ( I don't subscribe to general because I like getting *some* work done @ work - otherwise I'd just be 'at the ready' for support all day long - afaik it's fairly high traffic, yes?) er. yes :-) actually i talking with a couple of guys off list about building a 'parrot' which will auto answer newbie-emails :-) Cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] if statement
Craig Hoffman wrote: Hi There, I am trying to write an if statement to see if an array has any values in it and if it does do something. for example: $ticklist2 = array('$values) if (array_values(empty($ticklist2))){ empty() is used to check whether a var isset and is not null, or false - and it returns a boolean value not an array; php -r ' $a = null; $b = false; $c = ; var_dump($a,$b,$c); if (empty($a)) { echo \$a is empty.\n; } if (empty($b)) { echo \$b is empty.\n; } if (empty($c)) { echo \$c is empty.\n; } ' array_values() expected an array as its argument. maybe it can auto-cast any var it receives to an array but I don't know (I never use it like that anyway.) what is does do return an array with an associative keys 'replaced' with numeric keys - come to think of it I don't use this function at all. any have a good use for the function, just out of interest? if you want to remove empty values: php -r ' $a = array(yeah, null, , yeah, baby!); var_dump($a,array_filter($a)); ' if you want to remove empty values and duplicates: php -r ' $a = array(yeah, null, , yeah, baby!); var_dump($a,array_unique(array_filter($a))); ' do something } else { do something else } php -r ' $a = array( null, null ); var_dump($a); if ($a) { echo \$a has items.\n; } if ($aCnt = count($a)) { echo \$a has {$aCnt} items.\n; } $b = array(); if ($b) { echo \$b has items.\n; } if (empty($b)) { echo \$b is empty.\n; } $c = array(f = me); if (!$c) { echo \$c is empty items.\n; } if (!empty($c)) { echo \$b is empty.\n; } ' I just can't get this to work. Any help would be great. http://nl2.php.net/echo http://nl2.php.net/empty http://nl2.php.net/var_dump http://nl2.php.net/array http://nl2.php.net/array_unique http://nl2.php.net/array_filter Thanks, Craig H. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] works on command line, not on server
The Disguised Jedi wrote: try users@httpd.apache.org list On Tue, 25 Jan 2005 14:21:25 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have a new installation of php on an existing apache 2 server, and something strange is happening. The file 'test.php' works and connects to the database when run through the command line, but when run from the web server (http://server/test.php) produces a segmentation fault: child pid 29056 exit signal Segmentation fault segmentation faults are a built in feature of the PHP/Apache2 setup whenever you don't use the PREFORK Apache2 worker module - I know barely enough to know this - this is due to threading (which is not supported with ?most? php extension - not sure if php itself has this problem also). Anyway bottom line switch to PREFORK worker module if your not already using it, alternatively you could try to get a stable threaded setup going but before you embark I'd like to paraphrase a higher PHP authority, Rasmus Leidorf (they don't get any higher actually) speaking in relation to using a threaded Apache2 worker module: Your in unchartered territory, good luck. and Nobody knows. php itself does work, and a file with only phpinfo() in it runs fine on both the server and the command line. Has anyone seen anything like this before? Any ideas? ?php $link = mysql_connect(localhost, user, pass) or die(Could not connect); mysql_select_db(disorder) or die(Could not select database); print hello; also you may need/wish to try the newer mysqli_* extension which is geared to the latest versions of MySQL. ? -- 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] firebird - equivalent of stristr() in Stored Procedure.
hi Guys, I'm using Firebird 1.5 with PHP5. I have a problem where by I am trying to do the equivelant of: $a = 'A'; $b = 'AG'; if (stristr($b, $a)) { // do something. } Inside a Stored procedure, where $a and $b are both input variables to the stored procedure. The Interbase Lang Ref (PDF) doesn't help me here - I've tried all sorts of forms of syntax using CONTAINS and LIKE but it all gives syntax errors... (which didn't surprise me!) Then I thought that I could used Ard Biesheuvels php_ibase_udf UDF lib for firebird, php_ibase_udf.c is in the php cvs (somewhere); this lib allows access to php functions defined in your calling scripts. at any rate I get BLR type errors when I tried to use the UDFs (btw googling php_ibase_udf.c doesn't return a lot, but you will definitely find one email mentioning the BLR error!!). Actually I have tried setting up this UDF lib on 3 different servers (all fbird1.5/php5 - different minor versions) with out any luck. does anyone have a clue as to how do the equivalent of the PHP above inside a firebird stored procedure? or possibly can point out so good literature/examples (all the good firebird stuff seems to be in russian) on/of 'advanced' stored procedures. alternatively is there anyone out there that has gotten the php_ibase_udf UDF lib to work (Lester Caine have you tried it yet?, I ask you specifically because your name often pops up on php lists in relation to firebird :-). before any says: why not ask the developer - we'll his is an aquaintance of mine, I have his mobile number and I have asked him!, its just a case of he has _no_ time (due to dissitation/research commitments) to dig into the problem and I know that he will help when he gets some free time again, but for now I'm on mine own. hope somebody can give me a clue :-), thanks and regards, Jochem -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] firebird - equivalent of stristr() in Stored Procedure.
Jochem Maas wrote: hi Guys, hope somebody can give me a clue :-), well about 5 mins after I posted I managed to find a solution thanks to a man named Ivan Prenosil (who by all accounts knows where his firebird towel is ;-) http://www.volny.cz/iprenosil/interbase/ip_ib_code_string.htm (the stored procedure named 'Pos' on that page was basically what I was looking for.) btw - if somebody at google decided to throw all the Mozilla related references to the word 'firebird' out of the F** indexes I wouldn't loose any sleep over it. thanks and regards, Jochem -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] works on command line, not on server
[EMAIL PROTECTED] wrote: Thanks, I already had prefork installed. I solved the problem by heaven help those that walk the threaded path heh :-) changing to php 5 from php 4. IC interesting to know. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Define constants: awkward usage?
tony wrote: Hi all, I got this sets(20) of defined constants which using them as keys to an array eg define(FNAME, fname); farray = array( FNAME = hello ,...); my question is how do I insert that directly into a javascript(to do some client validation) I need this: var fname = document.addrform.fname.value var fname = document.addrform.{FName}.value//don't work var fname = document.addrform.{'FName'}.value//don't work var fname = document.addrform.[FName].value//don't work I know this work, but messey $tmp = FNAME; var fname = document.addrform.{$tmp}.value you could try sprintf()/printf(): $output = sprintf('var fname = document.addrform.%s.value', FNAME ); or printf('var fname = document.addrform.%s.value', FNAME ); I'am finding the use of define constants rather awkward. does anyone make much use of them? yes. :-) for... session varnames post/get varnames bitwise flags er...? Thanks Tony -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Really Stuck!
Ben wrote: Hello all, As a beginner I have been trying to send two attachments from my HTML form. the code you posted has no baring on DB stuff. so probably you question was better aimed at php-generals, anyways Below is the code I have been using. The problem is, I seem to only be able to send one or the other, when I send both, although they go through, the text I want displayed tags 6110 etc, is also sent as an attachment. Any help would be greatly appreciated as I have a huge headache! not surprised, anyway save you self more headache - get phpmailer instead, some smart guy(s) has done all the work for you :-) phpmailer.sourceforge.net -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Double Inserts
Bastien Koert wrote: post code...can't read minds, you know ;-) cant-help-myself style=no-disrespect-to: bastien; well yes, you have to understand Bastien is only an apprentice has not yet been initiated into the inner mind-readers circle. I on the other hand can tell you with utmost certainty that the solution is 42 /cant-help-myself give us code so we can get our 'helpers' fix :-) Bastien From: [EMAIL PROTECTED] (PHPDiscuss - PHP Newsgroups and mailing lists) To: php-db@lists.php.net Subject: [PHP-DB] Double Inserts Date: 25 Jan 2005 17:32:28 - Hi, I am new to the mailing list and to PHP / MySQL. I am facing an unususal problem. I am trying to insert some data into MySQL DB through via Web. The code is executed OK - no errors but the same record gets inserted TWICE. I have checked the code and simplified it as much as possible and tried test scripts with same results. I have also tried statements to echo messages to ensure the code is not executed twice. It happens with IE as wells as Mozilla so I don't think it is a browser issue. The only clue is that it does not seem to happen on a slower machine (Laptop). The configurations, versions etc are identical - Apache 2.0.49, MySQL 4.1.6-gamma-nt, PHP 5.0.2 Has anyone faced this and found a solution? Please help. Shri -- 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] Double Inserts
Martin Norland wrote: Bastien Koert wrote: I am but your padawan brilliant. Bastien [snip] From: Jochem Maas [EMAIL PROTECTED] cant-help-myself style=no-disrespect-to: bastien; well yes, you have to understand Bastien is only an apprentice has not yet been initiated into the inner mind-readers circle. I on the other hand can tell you with utmost certainty that the solution is 42 /cant-help-myself [snip] In all fairness, I'd say Bastien is a frood who really knows where his towel is[1]. He's surely finishing up his apprenticeship. 1 http://hhgproject.org/entries/towel.html ditto. :-) Cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] IIS, PHP, and session data
Perry, Matthew (Fire Marshal's Office) wrote: I am having trouble with my session data on Microsoft IIS. Here is a little background of the problem: 1) I am not personally in control of our web server. Our IT department manages it. They have IIS running on their sever and use MS SQL Server, but they have allowed me to use PHP instead of ASP. 2) I have Apache running on a local web server in our office (not the IT department). It accesses the SQL Server database remotely. I have register_global turned OFF and use the following code on each page: session_start(); session_register('logged_in'); session_register('username'); have you tried using the $_SESSION superglobal instead? you dont state the versions of php btw. ... Thank you for your time, Matthew Perry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Auto Responses?
Nigel Jones wrote: Problems guys... Emails don't actually come from [EMAIL PROTECTED] they are sent to [EMAIL PROTECTED] and then sent like it was an email from the sender to x subscriber... Really you should be suggesting that the subjects be used in the event/filter things. Autoresponders DO have their uses (business people, as long as they aren't using their business account for lists) to ones that are, sign up for a free hotmail/yahoo/gmail/* webmail account and get php list stuff sent there instead (there are many people on this list with free gmail invites if you still need them). That or ask your network I don't use autoresponders - If I ever go away, I either: a, take a laptop and check for urgent stuff. b, send important clients/colleagues an email saying when I'll be back - which takes roughly the same time as setting up the autoresponder and has the added bonus that you don't have to remember to turn off the auto-responder when you get back ;-) having said that I'd love a gmail invite - I wanna dig into their madhatter javascript used in the clientside interface and learn a few tricks. so if anyone has a spare ...? admin/postmaster/yourself (if your that lucky) to setup another account for you ... This is getting way off topic. I don't use any autoresponders on my mail client so I can't give any advice there (but I'm sure google can). I only use autoresponders on my mailserver. These look at the headers of the incoming mail to determine whether an autoresponse is appropriate. The autoresponders will also limit the number of autoresponses so that if eg your friend sends you 100 mails, they will not be told 100 times that you're having a whale of a time in Hawaii, it will only frustrate them and foment envy :). BTW: Jason what server side autoresponder are you using? ... rgds, Jochem -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Auto Responses?
Martin Norland wrote: Jochem Maas wrote: Nigel Jones wrote: Problems guys... Emails don't actually come from [EMAIL PROTECTED] they are sent to [EMAIL PROTECTED] and then sent like it was an email from the sender to x subscriber... Really you should be suggesting that the subjects be used in the event/filter things. On that note - why is it that vacation autoreplies get through to this list, but if you dare to speak the dreaded o f f - t o p i c or [ O - T ] keywords your mail doesn't get through? its a mad world. :-) I don't use autoresponders - If I ever go away, I either: a, take a laptop and check for urgent stuff. b, send important clients/colleagues an email saying when I'll be back - which takes roughly the same time as setting up the autoresponder and has the added bonus that you don't have to remember to turn off the auto-responder when you get back ;-) Assuming you have this luxury. A bigger question is, how often are 'we' (e.g. techies) in positions where we're away for so long, and so immediately available to clients - but those clients don't know our schedule? If I'm so 'in bed' with a client that they expect instantaneous turnaround, I would just warn them directly - maybe my experiences are unique. I just don't service a lot of people at a time - I would think anyone who does either keeps communication open or has others servicing them also. good point, I indeed have the luxury of having a limited no. of (relatively important) clients, this makes things easy. having said that I'd love a gmail invite - I wanna dig into their madhatter javascript used in the clientside interface and learn a few tricks. so if anyone has a spare ...? Martin delivered the goods! many thanks to him, and anyone else who would have sent one (if Martin hadn't gotten there first :-) ) rgds, Jochem Done. Cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Out of the Office
Hutchins, Richard wrote: Agh! You have GOT to be friggin' kidding me! chill. These autoresponders and the whole discussion of how they work or don't work are just cluttering up this list. true. Please just everybody do everybody else a favor and _think_ before you use/configure your autoresponder and take the whole other discussion (while one of those is definitely not going to happen in the near future :-) I'm sure it has merit) off list. who is it that is supposed to admin this list? the person responsible doesn't seem to have the time (and/or the problems are not critical enough to warrant attention). is there anybody on this list capable of doing the admin? would they have some time to do it? and if so is there any possibility of giving such person karma to do some clean up etc? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Given only one mySQL user account by Host Company
Shay definitely has bad hosting. the guy wants a seperate mysql user with readonly privileges on his DB which is good practice. only ... his hostingco. has given him a single DB and a single user a/c. no doubt they manage their system via a webinterface - when every they add a customer, they check the box marked add MySQL DB to hosting package and click go. I bet that Shay does not have access to the MySQL system tables - like he said, the user a/c he has been given any grant privileges (at least that what I think he meant) Bastien Koert wrote: What admin tools do you have for the db? PhpMyAdmin? something else? Many of those can be used to create additional user accounts with more limited restricitions. Bastien From: Shay [EMAIL PROTECTED] Reply-To: Shay [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Given only one mySQL user account by Host Company Date: Sun, 23 Jan 2005 03:03:26 -0700 My hosting company gave me one database and one root user account, and I have no access for priviliges at all. So as far as I can tell, the only way for me to connect to the database on my site is to do a mysql_connect(host, user, pass), where the user and pass are the ones for this one super account. Is this a major security concern or what? Is there a way around this, or a way to minimize security problems? I've emailed them about this, and they act like they have no clue what I'm talking about: I'm not trying to hide files or directories, I'm talking about when I use PHP and make a connection to the database using mysql_connect(host, user, pass). This script is what is in my webpages that connects to the DB and retrieves data to print for users. Is there an anonymous account to use for retrieving data, or can I make one? Then the program or script you are using should have means for your users to access permitted areas. And there is no anonymous account, there is only your own account Db Now. Hosting company provide your site with tool for you to use your own programs and it's up to you which programs and how you use them. Our job is to make sure the tool is working. Other than that, we do not provide support for scripts and the programs you are using. If you having problems to use some programs then you need to get in touch with developers and find what need to be done and how. boilerplate idiots. -- 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] GROUP BY? Urgent help needed with selection list
Chris Payne wrote: Hi there, The problem is, the database is imported from a huge properties database and can only be imported in the format from the central database of estate agents, so I can't reformat it in the tables itself. Each table has the same fields, but one is for condo's, one is for you need UNION - use of the UNION clause assumes 2 things: 1. all the tables in question do indeed have identical columns 2. the UNION clause is supported by the version of your DB software having said that if you are importing the data and each 'table' is of the same format why not just import each file/table into 1 table in your DB? residential etc . however, the client need to be able to do a search all tables query, and bring the results up as though you are only search 1 table. I've never searched multiple tables before without a relative ID, what I need is to search all of them as though it is just searching 1, so I don't think multiple queries would work, hence why I'm trying to do it all in a single query. Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Cannot load MySQL extension (mysql.so issues)
franciccio wrote: Eve Atley ha scritto: Platform: Redhat Linux Enterprise WS 3 PHP installed: 4.3.2 MySQL installed: 4.0.21 Apache installed: 2.0.46 When setting up PhpMyAdmin today, I got the error: Cannot load mysql extension, Please check PHP configuration My phpinfo() shows: 'with-mysql=shared,/usr' (yes, the comma is not a mistake) - This looks like a glitch; should I fix, and if so where? Mysql.so was found in: is the file _actually_ called 'Mysql.so' the capital M would see to it that the extension is not found. sorry I can't help you any further. /usr/lib/php4/ My php.ini has been editted to read: extension=mysql.so ...and I also tried: extension=/usr/lib/php4/mysql.so Any clues on remedying this problem, without upgrading MySQL? I have read the problem is solved by installing a PHP-MySQL package, but when I attempted to do so via up2date, I was notified that a dependency was required for a MySQL-client. But Mysql is already installed and running. Any clues out there? Thanks, Eve Wrong thread and group. Bye normally I would agree with franciccio's remark (and I can't be too hard on him either cos he gave me a good explaination on JOIN stuff just yesterday!) BUT women deverse preferential treatment in this environment. here is why: rant a, IT is a 'male' (read: autistic ;-) social culture - why expect women to fit right in when they have different (read: higher ;-) social skills (in general). b, there are not enough of them in IT let alone the PHP world. c, they might be good looking and live round the corner from you ;-). the more women in IT the better it is for all of us - it gives us more social power as a group and makes us more balanced + you'll often find women have novel/new ways of looking at problems that a male mindset is less likely to consider. women/girls deserve a little more leaway when entering this little world. if only because men have been jacking them around for the last 5000 years - which has only brought us war religion ;-) /rant oh hang on - Eve did pretty much everything right in writing up her question to the list (setup details, context, explaination of things tried, consiseness etc etc) the only thing she may have done wrong is in the choice of list (possible php-general or php-install could have been a better choice). so thats another reason to cut her some slack. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Cannot load MySQL extension (mysql.so issues)
Eve Atley wrote: women/girls deserve a little more leaway when entering this little world. if only because men have been jacking them around for the last 5000 years - which has only brought us war religion ;-) ROTFL!! Too funny. :) thanks. :-) I got the issue somewhat resolved. I was being a slacker and wanted to administer MySQL with phpmyadmin, and I thought it would be an easy fix, but your not using MySQL in combination with php (other than the attempt to run phpmyadmin)? I opted for the command line eventually. While phpmyadmin still doesn't work despite mysql.so existing on my system (Mysql.so was Outlook insisting on proper capitalization), I got everything else working, in this particular case MySQL, via the command line. You said your using RedHat, do you have a choice in that?, are you okay with linux? Give SuSE a shot - as a distro is much better, german engineering and that and its got the backing, now that Novell has taken over shop (Novell of IT excellence, as opposed the marketing finesse of RedHat). for a little more extreme try Debian - if you can handle using a bash shell you will find it joyful, its start off with `aptget`, a few configures, make, make installs, zoom. Im no expert but I can setup servers ok, I just FTFM and it takes me a while :-) and lately Ive been setting up a fairly complex php webshop/site/cms type thing for a company that insists on redhat server bla bla bla edition - and its a nightmare - try setting up php5/firebird1.5/apache argh - well the guy that set it up said argh and next to me he's an honest to god wizard! they have it set so that technically you have to login to a website of redhat and the site logs into your machine and finds out whats installed, which it then reports back to you on the site. WTF!!! its pure madness. a man obviously thought this up. straight up. in my world: 1. RedHat - like treading in something brown and steaming. 2. SuSE - like driving in a Mercedes, but not always a brandnew one. 3. Debian - spaceship (or more precisely: The Tardis). which would you choose? just MHO And I posted here, assuming it was linked between PHP and MySQL, being that phpmyadmin is written in PHP and works off MySQL. Does not appear to be the case however! I didn't quite get it either! Thanks, Eve -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
OR SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername as Username FROM tblSubscribersChoices a LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode ORDER BY Username ASC and if that works but doesn't give you repeat records try adding the DISTINCT keyword after SELECT. snip Why are you so intrested in LEFT JOIN? I cn't help much since i don't I'm not but his original query used JIONs and a LEFT JOIN is (IMHO) the easiest to understand. I didn't have the presence of mind to rewrite the query using a simple WHERE clause - hope your tip helps him. btw: can anyone say if the LEFT JOIN or the alternative WHERE statement (in general?) is faster? know the schema of the db and i can't see clear the meaning of the tables in the query. Anyway try this: SQL SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername as Username FROM tblSubscribersChoices a, tblUser c, tblSubscribers b, tc_countries d WHERE c.fldClientID = a.fldChoice AND b.fldID = a.fldClientID AND d.fldCode = b.fldCountryCode ORDER BY Username ASC /SQL Bye -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
Martin Norland wrote: Jochem Maas wrote: I'm not but his original query used JIONs and a LEFT JOIN is (IMHO) the easiest to understand. I didn't have the presence of mind to rewrite the query using a simple WHERE clause - hope your tip helps him. btw: can anyone say if the LEFT JOIN or the alternative WHERE statement (in general?) is faster? I can't speak to the speed, although since JOINs (can) do more than simple matching, I'd say the where condition may turn out a little better (after crossing fingers that mysql will use the proper indices in all cases). An example of something I can't think of how to write into a where clause (easily, at least): from http://dev.mysql.com/doc/mysql/en/JOIN.html : If there is no matching record for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find records in a table that have no counterpart in another table: mysql SELECT table1.* FROM table1 -LEFT JOIN table2 ON table1.id=table2.id -WHERE table2.id IS NULL; I remember reading that now - last time I did major surgery with MySQL - it had to do with loads of IFNULL and CONCAT statements - thats where the specifics of the LEFT JOINS (null values produced) came in (must have stuck in my head). The 'explain' syntax can give you some idea of this, as well as help you in optimizing indices and queries. never did quite understand the explain output. :-) http://dev.mysql.com/doc/mysql/en/EXPLAIN.html Cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
Basile Francesco wrote: In general, you should not worry about faster query sintax, since mysql should (but i'm not sure) have an optimizer inside wich translate your sintax query in a better efficient one. Anyway, the where statement is perfectly equal to the join operator, it is called, in general, theta-join and in this case it is called equi-join (equi...because in the where statement you only compare attributes by the '=' operator). The only reason you want to use the left-join, which is a particular case for a general outer-join, is if you want to fill your result with NULL values rather than an empty records. cheers for that :-) I remembered something along those lines but the specifics of JOINing always leak from my head. :-) Jochem Maas ha scritto: -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql - image storing
Martin Norland wrote: Joseph Crawford wrote: Jason, can you explain why stripslashes should not be used on data taken from the db? when you store data in the db i thought it was good practice to addslashes, when you retrieve from the db, you will need to use stripslashes to remove the extra \ The slashes are added for the database, not to be stored with the data. for e.g. - to store: I've just eaten. you do: INSERT INTO status (hunger) values ('I\'ve just eaten.'); I was always under the impression that single quotes (assuming you are delineating you args with single quotes) should (officially) be escaped with another single quote - although backslash also works: INSERT INTO status (hunger) values ('I''ve just eaten.'); ...alot of really old code of mine is full of stuff like: $var = str_replace(','',$var); but maybe that just MTAM(tm) working for me - (thats a reference to a bit of humour from another thread btw - MTAM is not a technology :-) which stores: I've just eaten. It's not good practice - it's required (if you're not using a mechanism that already handles this - such as the latest mysqli bind functions) - otherwise the query is invalid. nice to learn that mysqli is getting it 'right' :-) [makes mental note to look into it!] You may be thinking of running 'htmlentities' when retrieving data - which is necessary in some cases, depending on where you're using it (most notably - in html where you don't want html output). Cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql - image storing
Joseph Crawford wrote: Jason, can you explain why stripslashes should not be used on data taken from the db? when you store data in the db i thought it was good although 'slashing' text works pretty much all of the time (possibly the guys using exotic encodings all day will say different :-) but the data you are storing in the DB is binary - stripping and slashing will probably do weird things to the data: try creating some image data and run it thru add_slashes() and stripslashes() and compare the output of each with the original. practice to addslashes, when you retrieve from the db, you will need why is it good practice? (anyone)? sounds like pure overhead to me. you could look up 'magic quotes' in relation to this, its often where the trouble starts! on a side note: - me I use the ibase/firebird php extension which has parameterized queries - so I can say goodbye to mysql_escape_arg() (or whatever the damn function is called) and having to hand craft lots of arg checks - but alas you may not have access to a firebird DB. to use stripslashes to remove the extra \ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql - image storing
Simon Rees wrote: On Tuesday 18 January 2005 19:18, Jochem Maas wrote: I was always under the impression that single quotes (assuming you are delineating you args with single quotes) should (officially) be escaped with another single quote - although backslash also works: I think it depends on the database that you are using. Oracle and MS-SQL both require quotes to be escaped with another quote, MySQL uses backslashes. I seem to recall that two quotes is the standard... Of course it is even better to use bind vars and then you don't need to escape the quotes (or worry about sql injection attacks)... did I mention I have been using firebird and the php-extension for the last year and a half ;-) cheers Simon -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql - image storing
Martin Norland wrote: Jochem Maas wrote: I was always under the impression that single quotes (assuming you are delineating you args with single quotes) should (officially) be escaped with another single quote - although backslash also works: INSERT INTO status (hunger) values ('I''ve just eaten.'); ...alot of really old code of mine is full of stuff like: $var = str_replace(','',$var); but maybe that just MTAM(tm) working for me - (thats a reference to a bit of humour from another thread btw - MTAM is not a technology :-) AFAIK - for Sybase and CSV yes, otherwise no (in general). Maybe it's a compatibility option? Still, there are perfectly valid reasons to have multiple ''s. (why, there's one now - sort of...) ok - cheers, just for the record If I wanted to insert your sentence: 'Still, there are perfectly valid reasons to have multiple s' :-) Cheers, -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP 5.0.3 and Oracle9i on Windows 2000/Apache
Chaun Keating wrote: I am having trouble logging onto Oracle via PHP on a Windows 2000 machine. I keep getting the error: Fatal error: Call to undefined function OCILogon() in C:\Program Files\Apache Group\Apache2\htdocs\oraconnect.php on line 15 I seem to have everything set up correctly. I am running an Oracle 9i client and have set up the php.ini file with extension=php_oci8.dll uncommented, left ;extension=php_oracle.dll commented. (Although I have tried various combinations of these two. Also I have set the extension_dir = C:\Program Files\PHP\ext correctly and noted that php_oci8.dll and php_oracle.dll exist there. Now here is where it gets really weird and I could use some help: It works fine from the command line: possibly the cli version of php is using a different ini file than the apache2 module/cgi. also you made need to restart apache in order to reread the php.ini file. with regard to putenv() - you may be suffering from safe_mode being on. also, (I don't know this!), if putenv is setting env vars whose scope is server-process wide then concurrent scripts _maybe_ messing each other up: e.g. request1 starts and does some putenv()s, request2 does the same a fraction later, request1 finishes and resets stuff done by putenv(), request2 trys to connect...which fails because the env vars are empty. I type php oraconnect.php for the following code: ?php //putenv(ORACLE_SID=TESTDB); //putenv(ORACLE_HOME=C:/oracle/ora92); //putenv(TNS_ADMIN=C:/oracle/ora92/network/admin); $username = SCOTT; $passwd = TIGER; //$db=(DESCRIPTION= // (ADDRESS_LIST= // (ADDRESS=(PROTOCOL=TCP) //(HOST=orahostname1)(PORT=1621) // ) // ) // (CONNECT_DATA=(SERVICE_NAME=TESTDB)) // ); $conn = OCILogon(SCOTT,TIGER,TESTDB); if (!$conn) { echo Connection failed; echo Error Message: [ . OCIError($conn) . ]; exit; } else { echo Connected!; } ? It works either way with the env_variables in the script or with them commented out from the command line. I just can't get it to work from the browser. Can anyone out there help me with this one? I have some experience with Oracle, Perl, and a little Java but not so much with PHP. Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Assistance on Query
Shannon Doyle wrote: Hi People, I would like some assistance on the following scenario. I have to pull out all records for a particular userid (easy enough) and then only show those entries where the follwing occurs. These records from the table will contain either an entry in the services_type field or the non_services_type field. What I need to do is show only those where the number of consecutive records that contain an entry in the non_services_type field is greater than or equal to 3 so example:- record 1 contains an entry in non_services_type record 2 contains an entry in services_type record 3 contains an entry in non_services_type record 4 contains an entry in non_services_type record 5 contains an entry in non_services_type record 6 contains an entry in services_type so I would need to display records 3,4,5 only Can anyone assist me with this? Could you explain what the logic behind doing this is. i.e. Why? (it might help to understand the problem, and possibly give a solution that does not rely on 'consecutiveness') I'm guessing you are using MySQL which is a relational DB, that means the order of records stored is essentially abstracted from the DB user, for instance using an ORDER BY clause will change the order of the result and therefore the 'consectiveness' of the values. It looks as if you will need to post-process the result set in PHP to get what you want, alternatively your DB may support stored procedures which could be an alternative (but harder to do than to do it in PHP) i.e. the stored procedure works out the correct rows and then outputs the result when you something like: SELECT * FROM getConsecServiceRows( 3 ) rgds, Jochem Cheers, Shannon -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Assistance on Query
Shannon Doyle wrote: Hi Jochem, My apologies, when I typed consecutive, I meant by date. Basically the query is for a report. The client wants to be able to see when there have been 3 or more entries of non_services_type between services_type entries, and then display these entries. I am using MySQL and would Order the entries by date. I hope that clears things up a little. yeah! I can't think how to do that offhand in SQL but in php it would go a little like this...(I'm assuming an array of results is being passed - where each item in the array is an object.): function filter3ConsecutiveNST($rows) { $output = $tmp = array(); $cNSTcount = 0; foreach ($rows as $row) { if ($row-type == 'non_service_type') { $cNSTcount++; if ($cNSTcount == 3) { $output =+ $tmp; $output[] = $row; $tmp = array(); } else if ($cNSTcount 3) { $output[] = $row; } else { $tmp[] = $row; } } else { $tmp = array(); $cNSTCount = 0; } } return $output; } hope that give you an idea. - Shannon -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Monday, January 17, 2005 1:37 AM To: Shannon Doyle Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Assistance on Query Shannon Doyle wrote: Hi People, I would like some assistance on the following scenario. I have to pull out all records for a particular userid (easy enough) and then only show those entries where the follwing occurs. These records from the table will contain either an entry in the services_type field or the non_services_type field. What I need to do is show only those where the number of consecutive records that contain an entry in the non_services_type field is greater than or equal to 3 so example:- record 1 contains an entry in non_services_type record 2 contains an entry in services_type record 3 contains an entry in non_services_type record 4 contains an entry in non_services_type record 5 contains an entry in non_services_type record 6 contains an entry in services_type so I would need to display records 3,4,5 only Can anyone assist me with this? Could you explain what the logic behind doing this is. i.e. Why? (it might help to understand the problem, and possibly give a solution that does not rely on 'consecutiveness') I'm guessing you are using MySQL which is a relational DB, that means the order of records stored is essentially abstracted from the DB user, for instance using an ORDER BY clause will change the order of the result and therefore the 'consectiveness' of the values. It looks as if you will need to post-process the result set in PHP to get what you want, alternatively your DB may support stored procedures which could be an alternative (but harder to do than to do it in PHP) i.e. the stored procedure works out the correct rows and then outputs the result when you something like: SELECT * FROM getConsecServiceRows( 3 ) rgds, Jochem Cheers, Shannon -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
Han wrote: Hi, I'm having a problem with some joins. My code is : -- SELECT b.fldName, b.fldEmail, b.fldCountryCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = b.fldID ORDER BY `c`.`fldUsername` ASC Now this works fine. But, I'm trying to tally the country code with it's actual name (which is held in tc_countries). So I thought if I add another LEFT JOIN at the end of the query : -- SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = b.fldID LEFT JOIN tc_countries d on b.fldCountryCode = d.fldCode ORDER BY `c`.`fldUsername` ASC But this just times out as it's matching too many matches. What am I doing wrong??? your not using the correct SQL, obviously :-) - that said there often many ways to get the result you want. what happens if you change the second SQL statement you quoted to: SELECT DISTINCT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = b.fldID LEFT JOIN tc_countries d on b.fldCountryCode = d.fldCode ORDER BY `c`.`fldUsername` ASC (I added the keyword DISTINCT to the query) Also you are using an INNER JOIN for the first join and A LEFT JOIN for the second one. what happens when you replace the INNER JOIN with a LEFT JOIN? Han. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
BTW: Hans please use 'reply to all' so that the rest of the list can see your replies (+ it makes me feel less like you personal help-desk ;-). ...on to the reply proper: Han wrote: Hi, thanx for replying. It still times out when I use either of those alternatives. can you tell what exactly the script is timing out on - i.e. are you sure its the call to the DB? you SQL _may_ not be the most efficient way of doing it (not that I know or anything) but I can tell you that I have a query on a production site which involves 16 JOINS and that works fine [I can here you laughing in the bach there ;-)] - actually it had 33 JOINS but there is a hard limit to the number of joins per statement in the version of MySQL the site uses so I had to split the query into 2! also have you tried running the complete query/queries directly in a MySQL console? i.e. remove PHP from the equation to determine if the problem is actually the SQL. please tell us whether the statements work ok when you run them directly. I've tried changing all the JOINs around and nothing works. Post the table deinfitions to the list + a recap on what you are trying to get as a result. I thought maybe there's a logic problem going on? some kind of problem anyway ;-) snip SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = b.fldID LEFT JOIN tc_countries d on b.fldCountryCode = d.fldCode ORDER BY `c`.`fldUsername` ASC in the orderby clause you apply backticks to the table alias 'c', which you don't do anywhere else. its a long shot but try removing those backticks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
Han wrote: Oh yes, sorry, not used to the reply-all. most of us get hammered by that one once in a while! read on the the interesting bit... I've pasted it directly into the MYSQL console as just sql and this is where I discovered my problem. My code is : -- SELECT b.fldName, b.fldEmail, b.fldCountryCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = b.fldID ORDER BY `c`.`fldUsername` ASC Now this works fine. But, I'm trying to tally the country code with it's actual name (which is held in tc_countries). So I thought if I add another LEFT JOIN at the end of the query : -- SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = b.fldID LEFT JOIN tc_countries d on lets look just at this last little bit of the statement: b.fldCountryCode = d.fldCode ORDER BY `c`.`fldUsername` ASC try changing this to: d.fldCode = b.fldCountryCode ORDER BY c.fldUsername ASC (I removed the backticks too, as you don't use them in the rest of your query, and that was irritating the aethetic monster within me ;-) Actually looking at your complete statement you _seem_ to have got all the JOINS backwards (I'm no SQL guru so I may be totally wrong here, besides which I don't know the DB-schema your using), does this work: SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode ORDER BY c.fldUsername ASC and if that works but doesn't give you repeat records try adding the DISTINCT keyword after SELECT. snip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
Han wrote: Hmm, still no luck. Thanks for the help. I think I'll have to break the you mean that it still times out? crashes mysql? maybe the table (tc_countries) is corrupt? try doing a repair. select up into 2 selects and throw the results of the first into arrays. Didn't want to do it like that, but it's gonna be quicker now. if at first you don't succeed... hack ;-) snip try removing the ORDER BY Clause: SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode ORDER BY c.fldUsername ASC OR SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername as Username FROM tblSubscribersChoices a LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode ORDER BY Username ASC and if that works but doesn't give you repeat records try adding the DISTINCT keyword after SELECT. snip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slow Query
Wendell Frohwein wrote: snip So I rewrote my script to do the follow: The client submits a property for an appraisal. Based on the appraisal type and property zip code, It does a radius search of 2 miles from the property zip. If no matches are found, it does a 5 mile radius search. For every zip code returned by each radius search, It searches the database for agents / appraisers with the zip code in question (zip codes from radius search) in there coverage. This is the most stressful part I am assuming. This works fine for 1 - 10 orders. But when I import 30 or more, the script pretty much hangs as well as mysql. I have to kill mysql with signal 9, start mysql it up again. Then all is back to normal. I would paste the code in here but it is really long and complicated. snip there was/is a thread going on at php-generals regarding zipcode-long/lat issues (you may have seen it). one of the things that came up is doing the joins on the tables in question (and/or doin the maths) is heavy work. I would imagine that the results for a given calculation (i.e. get postcodes with certain radius) stays the same, if they do then it may be an idea to do the calculation before hand and store the results in a way that its very fast to access e.g. writing out PHP arrays into files for later inclusion as required (possibly because new postcodes are occasionally added you may want that to trigger a recalculation - e.g. when a new postcode is added do the calculation then for all postcodes found do a recalculation for those as well!). so...It doesn't sound like you can get round the ammount of processing that needs to be done but maybe you can do it 'offline' and store the results for quick access when you need it? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Norland, Martin wrote: -Original Message- From: Stuart Felenstein [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 10:40 AM Subject: [PHP-DB] Update multiple records Having a problem here with updating multiple records in a table. [snip] Lets see - where to begin... SELECT * FROM `Profiles` INNER JOIN `Profiles_Industries` ON Profiles.ProfileID = Profiles_Industries.ProfileID) INNER JOIN IndTypes ON Profiles_Industries.IndID = IndTypes.CareerIDs) INNER JOIN SU ON (Profiles.kID = `SU.kID) WHERE Profiles.ProfileID = colname [snip] You list nothing indicating any sort of update, so forget that for the time being until things are working. That's your end goal, but it doesn't look to be what you're fighting with now. You have a very complicated (perhaps messy, perhaps not - it might all be required) select, and then you're trying to pull that information out and populate a select. INNER JOIN SU ON (Profiles.kID = `SU.kID) [snip] This line in particular clearly warrants attention. Cookie to whoever guesses what the' problem` might 'be. that will be a lone backtick then :-) now where's the cookiejar ;-) ?php $selected = explode(,,$rsLPInds-Fields('IndID')); while(!$rsInds-EOF){ ? option value=?php echo $rsInds-Fields('CareerIDs')? ?php if (in_array($rsInds-Fields('IndID'),$selected)) { echo selected; } ? ?php echo $rsInds-Fields('CareerCategories')?/option [snip] explode() turns an array into a string, you'll have trouble in_array()ing a string. You may want to start there. er Martin, no it does not. explode creates an array. the manual defines it as thus: array explode ( string separator, string string [, int limit]) possibly you got mixed up with implode() (or join() which is an alias of implode()) You don't list the select bit around your select, I'm assuming it's there - what actual behavior/output are you seeing? View source to be sure - you have to specify a select is a multiselect, otherwise it will just be a dropdown and select the first one you say is selected (or maybe the last, I've not messed with it in some time - actually, it's browser dependant, but I think they all tend to behave the same.) rsLPInds-Fields and rsInds-Fields - this is two objects/tables/etc. - you only mention the one, so it's hard to follow what data's where - to be sure. Try that stuff and get back to us. You definitely want to be using print_r() (possibly in pre tags) to see what information is actually stored in the results of your select statement, if there is any question there. - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Stuart Felenstein wrote: Having a problem here with updating multiple records in a table. as Martin Norland (a heavy hitter on this list AFAIKT) already stated you don't seem to be at the stage of actually doing an update, no big deal - only you are doing yourself an injustice by given a misleading subject. stick to the matter at hand (one step at a time!) - by all means explain the context of the problem (e.g. your goal of multiple updates) but don't confuse the problem with the context! I'm sure this is all most likely confusing. :) Typical I took one look and thought 'no thanks', if _you_ think _your_ post is confusing how is anybody else supposed to make head or tail of it. post from me ...sorry. None of this is working though. don't be sorry, be pro-active and rewrite it until its idiot proof. its in your own best interest - the clearer you state your problem the greater the chance someone will/can help you. ok, so that was a bit of a rant, the idea being to educate people in the value of taking the time (and it often takes lots of time!) to formulate their problems (and what they have tried so far) properly - its in everyones interest because it increase the potential of everyone on the list to: a, get involved b, learn something new we want you to succeed, if only for the selfish reason that one day you'll have the capability to help out others. besides the more good PHP hackers there are the better it is for all of us - in terms of the perceived validity of PHP (especially at the enterprise level). Perhaps updating multiple records is more difficult then I first imagined. alas we all have stories of spending countless hours trying to figure out whats seems to be very simple problems! Can anyone lend some advice , assistance ? not directly, but you may want to look into making your code more readable/flexible by not constantly switching in and out of PHP mode (i.e. using ?php ? everytime you want to output something.) Thank you, Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Norland, Martin wrote: -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 11:59 AM Subject: Re: [PHP-DB] Update multiple records ... That's what I get for troubleshooting before lunch! My apologies to the list and to anyone unfortunate enough to find that post with a search! I always get implode/explode mixed up (I think of an array as more organized than a string - so I think of a string as just an array that's been blown to smithereens). I guess the idea is that an array is like a bunch of pieces of a string after it's been blown up. thats actually why I personally always use join() instead implode(). also it does help beginners, the fact that its possible to use 'array syntax' on strings e.g.: $str = 'mystring'; echo $str[1] . ' me God?'; // echos 'y me God?' - say it out loud people ;-) I even checked the manual and dyslexically read it. 'Spose I owe everyone a cookie, and Jochem Maas two (plus first pick!). I quick google lead me to suspect Martin is american... if that is true then I demand one of those bigass cookies with even bigger chocolate chips :-) Cheers, - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Stuart Felenstein wrote: --- Jochem Maas [EMAIL PROTECTED] wrote: don't be sorry, be pro-active and rewrite it until its idiot proof. its in your own best interest - the clearer you state your problem the greater the chance someone will/can help you. I don't know about anyone else, but I haven't got a clue as to what the problem is. I know I'm fairly intelligent but I can't work it out. Well I've started with a clean slate. Meaning I always a good plan! ditched what was starting to look like spaghetti and started over with a lot of print_r's. My select statement in the (intended)update page has 3 is it an update script or a selection/view script or both? parameters in the where statement, that are passed over from the link using $GET_VARS. 1- is the recordID, 2-the userID 3-an encrypted code tied to the user. so you start with a page that submits three values to another page which works so that not the problem... All those parameters show up fine (print_r) on said update page. The first problem I'm having is getting the update page to show which values currently exist. what values are you talking about? currently exist where? This is the multi select box and the (adodb) recordset listing all the options. I'm lacking something in the page though that allow it to see which values are already chosen in the database: select name=inds[] size=8 multiple id=inds[] ?php while(!$rsInds-EOF){ ? option value=?php echo rsInds-Fields('CareerIDs')? ?php if (count($IndID) 0 AND is_array($IndID)) { use not AND unless you know what your doing! they are different. also you check the count() on $IndID before you check its an array! another thing: $IndID and $rsInds are pretty meaningless to the rest of the world, and they will be to you as well in 6 months time! use a few extra chars and give the vars meaningfully, easily idenfiable names (helps us guess what you are doing too!) foreach ($IndID as $ind) { ? ?php if ($rsInds-Fields('IndID')== $ind) {echo SELECTED;} } }? ?php echo $rsInds-Fields('CareerCategories')?/option ?php $rsInds-MoveNext(); } $rsInds-MoveFirst(); that looks evil; seeing as I a still have no idea what your actually stuck on I'll give you a quick lesson in writing neater/better code: // begin code sample --- $opts = array(); $IndID = (array) $IndID; while (!$rsInds-EOF) { /* is this option selected? */ $selected = in_array($rsInds-Fields('IndID'), $IndID) ? 'selected=selected' : ''; /* build the option */ $opts[] = sprintf('option value=%s %s%s/option', rsInds-Fields('CareerIDs'), $selected, $rsInds-Fields('CareerCategories')); $rsInds-MoveNext(); } /* output the complete select element, * you don't have to output directly!!! * you could stuff the strings into another * var and echo it out later (e.g. after all * processing has been done) */ echo 'select name=inds[] size=8 multiple id=inds[]'; echo join(\n, $opts); echo '/select'; $rsInds-MoveFirst(); // end code sample --- excuse the strange layout a, I like short lines. b, I find tertiary if statements very readable when spread across multiple lines. c, I'm try to avoid nasty linewrap due to mail setups. BTW - the above is not syntax checked. anyone care to say this is _not_ more readable? I've added this in the script, which prints out fine once I've submitted the page. Not sure if I need something similar for the records that already exist ? neither do I! if (count($inds) 0 AND is_array($inds)) { $ind = '.implode(',', $inds).'; } looks like you want to do a select statement with $ind in the form of SELECT * FROM yourtable WHERE yourfield IN ($inds) heh why not! Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] ssh tunneling with phpmyadmin
Jason Wong wrote: On Tuesday 11 January 2005 11:39, Graham Anderson wrote: is it possible to ssh tunnel with phpmyadmin I want to access my remote db [on shared server] from my phpmyadmin on my laptop my ISP wonderfully disabled phpmyadmin's relational features :( seems a bit hard to find the info so I thought I would ask here :) I am using Mac OS X if it matters Assuming you're able to SSH into the server from your laptop then run this on your laptop: ssh -fN [EMAIL PROTECTED] -L 13306:127.0.0.1:3306 classy tip! Then configure your laptop's copy of phpmyadmin to access MySQL using address 127.0.0.1 and port 13306. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] String Parsing/Escaping
hi Alexander, interesting question regarding 'safety' v. readability v. speed - I'm sure you'll get different views depending on who you ask. Here is my take: Alexander Mueller wrote: Hi, below are three versions of an SQL call along with escaping the passed value. $value=mysql_escape_string($_POST['value']); mysql_query('SELECT * FROM table WHERE field='.$value.''); + Fastest Code - Con: Bad Readability, Value needs to be escaped separately I rate speed as the least important issue - you can alway use a faster machine, get some more RAM etc if you really need a quick speed fix. making the code faster is the last exercise I do in any given project, and I almost always choose readability/'safety' over speed $value=mysql_escape_string($_POST['value']); mysql_query(sprintf('SELECT * FROM table WHERE field=%s', $value)); + Good Readability - Value needs to be escaped separately This is a compromise - can't imagine why anyone would choose this one. It's not my choice, I'll just skip to number 3 :-) sql_sprintf() is a custom version of sprintf() which automatically escapes all passed parameters. mysql_query(sql_sprintf('SELECT * FROM table WHERE field=%s', $_POST['value'])); + Good Readability, Value does not need to be escaped separately - Slowest Code YEAH! indeed its the slowest. but its so much more readable and you know its alot more maintainable (you don't have to change the escaping, sprintf'ing strategy in 100 places.). Its safer too because there is no chance of forgetting to escape the sql args. I think the speed difference can be measured in milliseconds - are you really worried about that? if your app is that heavy that you are trying to shave off milliseconds to make it usuable then there are possibly bigger problems. Imagine you have a highly dynamic page that does 50 queries (using the 3rd technique you proposed), I would guesstimate that refactoring the code to do 2-3 less queries per request would get just as much speed increase (if not more) than by refactoring the code to use the 1st technique on all 50 queries (granted you could refactor both but heh there are other things to do than code PHP 24/7 ;-) in order of importance to me (I often have to maintain/update my code): 1. security 2. readability/maintainability 3. speed/performance basically the more abstract your code is, the slower it will be - because you are asking it to do more for you. to me the extra milliseconds wait on a request are worth it, anything to avoid debug/maintainance hell! And if speed really is a big issue - you may need to look into writing part of you application logic as a PHP extension (i.e. in C which is way faster anyway you cut it.) ... Thanks, Alexander PS: All this code is considered to run under magic_quotes_gpc OFF. as it should be ;-) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL ENCRYPT help!
Kevin the Linux User wrote: To the PHP Database Mailing-List: I joined the mailing list for this one question I just can't figure out. nice, we help you and then you bugger off? - community spirit are go! I used the phpMyAdmin to create table. I placed one row in this table, I used the ENCRYPT function. How do I De-Crypt the data I just encrypted to use in my PHP code. I encrypted it, for security. If it's not a bother, can you also give a sniplet of example code, on just the part of de-crypting it, I know everything about connecting, and displaying, it's just the de-crypting I am having trouble with. the mysql manual states: ENCRYPT() ignores all but the first eight characters of str, at least on some systems. this is probably not what you want, besides which AFAICS its one way encryption. --- as you don't state what it is your trying to achieve (e.g. storing a passwd - in which there is NO reason to want to decrypt it - instead you should test a user given value against the DB by encrypting the user value), you also don't state what version of MySQL your using therefore its impossible to determine which encryption functions you have at your disposal in MySQL. here is a couple of pairs of enc/dec funcs that might help: AES_ENCRYPT(str,key_str) AES_DECRYPT(crypt_str,key_str) DECODE(crypt_str,pass_str) ENCODE(str,pass_str) try reading this page: http://dev.mysql.com/doc/mysql/en/Encryption_functions.html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL statement
PHPDiscuss - PHP Newsgroups and mailing lists wrote: Hello everybody, I'm building a small application and I have trouble passing a POST variable form one page to another inside the SQL statement. The query displayed below works great without the .$_POST['CompanyName']. $query_company_listing = SELECT CompanyID, CompanyName, CompanyOrDepartment, BillingAddress, City, PostalCode, PhoneNumber FROM company WHERE company.CompanyName=.$_POST['CompanyName']. ORDER BY CompanyName ASC; you need to quote the string (company name) in the actual sql, compare the following 2 statements (lets assume companyname is 'IBM'): WRONG (this is what you are doing now): SELECT CompanyID, CompanyName,CompanyOrDepartment, BillingAddress, City, PostalCode, PhoneNumber FROM company WHERE company.CompanyName=IBM ORDER BY CompanyName ASC RIGHT: SELECT CompanyID, CompanyName,CompanyOrDepartment, BillingAddress, City, PostalCode, PhoneNumber FROM company WHERE company.CompanyName='IBM' ORDER BY CompanyName ASC there may be times when the companyname contains a single quote - that will break your query unless you escape the single quote in the name before placing the string into the query string... mysql.com can tell you more. But it messes up if I include it because the first is considered as the end of the previous one and so on, so the code gets messed up. I'll really appreciate any/all help! Have you all an excellent year! Jorge -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] setFetchMode problem with mssql/w2003/php503
ltlists wrote: I'm getting this error when attempting to use setFetchMode() PHP Fatal error: Call to undefined method DB_result::setFetchMode() in new.php on line 27 which means that class DB_result does not have a setFetchMode() method. did you read past the colon (:) in the error message? did it cross your mind to search for the class that does contain that method?? My code looks like this for now, almost the same as some of the samples getting around: $db = DB::connect(mssql://blah:[EMAIL PROTECTED]/blah); if (DB::isError($db)) { die ($db-getMessage()); } $res=$db-query(select * from Contacts); if (DB::isError($res)) { print $res-getMessage() . \nDetails: .$res-getUserInfo(); } else { $res-setFetchMode(DB_FETCHMODE_ASSOC); If looks as if you are trying to call the setFetchMode() method on the 'resultset' object in your first example and in your second example (the function) you are calling the same method on the 'db' object. so this might work better: $db-setFetchMode(DB_FETCHMODE_ASSOC); I'm assuming $db is actually a a valid object of class DB $row=$res-fetchRow(); $field0=$row['ID']; $field1=$row['Name']; $res-free(); $db-disconnect(); } Just incase this could be an installation related problem I should explain that I am using this in a virtual PC environment with IIS6, PEAR was downloaded via a normal machine and then copied to the virtual PC and go-pear was run (I think that's it). A function based connection like this: function execute_query($db,$sql) { debug($sql); $db-setFetchMode(DB_FETCHMODE_ASSOC); return $db-getAll($sql); } seems to return data instead of erroring out. I'm just a bit lost as to why the first lot of code has a problem with DB_result. If anyone can help that would be great. Thanks for your time. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL statement
Jason, can you please turn off the return receipts on emails you send to the list. it's bloody annoying to have 'The Sender wishes to be notified' popup messages everytime I read one of your emails (and, alas, I don't have the skill to hack the return receipt crap right out of Tbird). BTW your not the only one that has it turned on - so this goes to the rest of you as well :-) cheers! Jason Walker wrote: First off - $_POST['CompanyName'] is valid, right? ... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] select text from a text file
Ed wrote: Hi, Thanks for answering the question. I'm going to make it write to a database rather than text file after searching google and coming accross common problems with text files. I've now just got to figure out how to mark the message as read in the database so it does not re-appear next time the user clicks update. TIMESTAMP? you can save in the session when a use last grabbed messages (clicked update) and only return newer messages (i.e. message have a 'created' timestamp) then update the timestamp in the session. there is a window in which it is possible to have a request inserts a new message in between another request's selecting of all new messages and updating the session timestamp value (in such cases the person at the client end of the second request will never see the new message insert in the first request) - to handle that you have to implement some kind of locking mechanism. good luck is all can say. (PHP implements a 'share nothing' architecture - not, perse, the easiest or most efficient type of system to build realtime multi-user environments in - AFAICT) I'm going to build a function that will put the message in the correct table using an if clause, is that the best method? your the best judge of that - heh if it works that's the main thing - making it work fast that's something to look at later... and then there is the issue of writing code that neat, tidy, well commented and readable 6 months down the line. Ed - Original Message - From: Andrew Kreps [EMAIL PROTECTED] To: Ed [EMAIL PROTECTED]; php-db@lists.php.net Sent: Thursday, January 06, 2005 6:55 PM Subject: Re: [PHP-DB] select text from a text file On Wed, 5 Jan 2005 11:58:59 -, Ed [EMAIL PROTECTED] wrote: Happy new year folks! The titlemight make this seem like an easy to answer question However here's the complicated bit (well for me anyway). In my text file that is written to by the users in a chatroom it looks like this: nickname||color||what the user is saying||user how can i make it so that if they have a private message when they press update it pulls the message from the text file and displays it in the frame but also deletes the text? You should be using a database for this, it makes things so much easier. That being said, here's one way to go about the text file version: Open the file, read through it line by line. As you read it, push the lines into an array. If you find a private message for the user, store that in a variable, and do not push it into the array. Finish reading the file. If there's a private message, you've got it in a variable, and you can overwrite the private message file with the array you've stored, which is all of the current private messages minus the one you're about to display. Please note, this does not scale at all, especially in the fast-paced world of chat rooms. You will likely end up with file locking problems if you proceed with the flat-file method. Also, how can i make it so that if in a drop down menu they select the word everybody it goes to a file called messages.txt and if they select user or user2 or user3 from the list it writes to private.txt is this at all possible? user and user2 etc arent hardcoded it's pulling the names from a list of online users. Are you talking about appending messages to a text file? In that case, you can have the dropdown submit with the message, and in the PHP code have a case for 'everybody' where it writes to messages.txt, and if it's not 'everybody', write it to private.txt with the username that was selected from the dropdown as part of the row. Does that answer your question? -- 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] select text from a text file
Ed wrote: Hi, The timestamp idea is an intresting idea and i'll give that method some thought. I only want it to pull one private message at a time out of the private message field so it might start getting very messy doing that method - but it certainly does make it worth considering. I see (I think) - the timestamp idea was aimed at a public general list of messages. in the case of private messages - they are always aimed at one particular user therefore in such a case a simple flag (true/false) to state whether its been viewed would probably work - or you could just delete the last grabbed message after you have selected it for output. have fun! Ed - Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Ed [EMAIL PROTECTED] Cc: php-db@lists.php.net Sent: Friday, January 07, 2005 11:37 AM Subject: Re: [PHP-DB] select text from a text file Ed wrote: Hi, Thanks for answering the question. I'm going to make it write to a database rather than text file after searching google and coming accross common problems with text files. I've now just got to figure out how to mark the message as read in the database so it does not re-appear next time the user clicks update. TIMESTAMP? you can save in the session when a use last grabbed messages (clicked update) and only return newer messages (i.e. message have a 'created' timestamp) then update the timestamp in the session. there is a window in which it is possible to have a request inserts a new message in between another request's selecting of all new messages and updating the session timestamp value (in such cases the person at the client end of the second request will never see the new message insert in the first request) - to handle that you have to implement some kind of locking mechanism. good luck is all can say. (PHP implements a 'share nothing' architecture - not, perse, the easiest or most efficient type of system to build realtime multi-user environments in - AFAICT) I'm going to build a function that will put the message in the correct table using an if clause, is that the best method? your the best judge of that - heh if it works that's the main thing - making it work fast that's something to look at later... and then there is the issue of writing code that neat, tidy, well commented and readable 6 months down the line. Ed - Original Message - From: Andrew Kreps [EMAIL PROTECTED] To: Ed [EMAIL PROTECTED]; php-db@lists.php.net Sent: Thursday, January 06, 2005 6:55 PM Subject: Re: [PHP-DB] select text from a text file On Wed, 5 Jan 2005 11:58:59 -, Ed [EMAIL PROTECTED] wrote: Happy new year folks! The titlemight make this seem like an easy to answer question However here's the complicated bit (well for me anyway). In my text file that is written to by the users in a chatroom it looks like this: nickname||color||what the user is saying||user how can i make it so that if they have a private message when they press update it pulls the message from the text file and displays it in the frame but also deletes the text? You should be using a database for this, it makes things so much easier. That being said, here's one way to go about the text file version: Open the file, read through it line by line. As you read it, push the lines into an array. If you find a private message for the user, store that in a variable, and do not push it into the array. Finish reading the file. If there's a private message, you've got it in a variable, and you can overwrite the private message file with the array you've stored, which is all of the current private messages minus the one you're about to display. Please note, this does not scale at all, especially in the fast-paced world of chat rooms. You will likely end up with file locking problems if you proceed with the flat-file method. Also, how can i make it so that if in a drop down menu they select the word everybody it goes to a file called messages.txt and if they select user or user2 or user3 from the list it writes to private.txt is this at all possible? user and user2 etc arent hardcoded it's pulling the names from a list of online users. Are you talking about appending messages to a text file? In that case, you can have the dropdown submit with the message, and in the PHP code have a case for 'everybody' where it writes to messages.txt, and if it's not 'everybody', write it to private.txt with the username that was selected from the dropdown as part of the row. Does that answer your question? -- 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] Fetch data from dbf file?
Supri anto wrote: hi all, did anyone know how to fetch data from dbf file (Clipper) ? use some code. don't expect too much help if all you can be bothered to write are single line questions. I googled 'DBF + PHP' and came up with this: http://half2.mirrors.phpclasses.org/browse/package/1302.html now I'm pretty sure they have google in your country too, so why don't you use it before coming onto a mailing list and expecting other people to do your research for you? best regards, suprie -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] php problem
Serenity Schindler wrote: I am new to php and have no idea what I'm doing wrong. I have a file named test.php containing: html head title PHP Test /title /head body pThis is an HTML line p ?php echo This is a PHP line; phpinfo(); ? /body /html The html lines show up just fine but none of the php info is displayed. Any ideas? does your page show you the text This is a PHP line? if you view the source of the page in your browser do you see the following: ?php echo This is a PHP line; phpinfo(); ? if so then PHP is not either: 1. your webserver is not configured to use php to handle files with a php extension. 2. your webserver does not have php installed. if not then try a file containing just the following and see if that outputs anything: ?php phpinfo(); ? ~Serenity~ - Do you Yahoo!? Yahoo! Mail - You care about security. So do we. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP query to mysql database returns emtpy data, but Query Browser shows records
graeme wrote: Hi, You have: $query example = SELECT description from cpProducts where category='39 47 48 172' don't you want to add a logical operator such as OR, possibly AND $query example = SELECT description from cpProducts where category='39 OR 47 OR 48 OR 172' graeme. whatever it is that he is trying to do - I doubt he wants to put 'OR's in the character string, besides which AFAIK you can't do something like: SELECT description from cpProducts where category=39 OR 47 OR 48 OR 172; (possibly the SQL above will actually return all rows because any number greater than zero will evaluate to true - e.g. ($x = true || 1) is always true regardless of the value of $x, I am assuming the same general logic goes for SQL or'ing) it should be: SELECT description from cpProducts where category=39 OR 47 OR 48 OR 172; Jason, read on for more (possible) help (well I gave it a shot but I don't think it will be any help, sorry): Jason Walker wrote: Here is the query: function ReturnPackageDescriptions($pack, $cat, $hotcat, $hotid){ $comIB = $cat . . $pack . . $hotcat . . $hotid; $catLength = strlen($comIB); echo $catLength; $query = SELECT description from cpProducts where category=' . $cat . . $pack . . $hotcat . . $hotid . '; echo bR . $query . br; echo combined package number = . $comIB . br; $retval = ; $link = mysql_connect($config['host'],$config['user'],$config['pass']) or die(Could not connect); mysql_select_db('stc_store') or die(Unable to connect to the default database); $result = mysql_query($query) or die(Unable to pull the menu objects for main event details); echo mysql_affected_rows() . br; while ($results = mysql_fetch_array($result, MYSQL_ASSOC)){ extract($results); echo $description; $retval = $description; } mysql_free_result($result); mysql_close($link); return $retval; } I have some extra 'echo' statements to see the progress on the web page. If I remove the 'where' clause within the SQL statement, I get rows. But when I add the 'where' portion, no records are returned. Here is an example of what the query looks like: $query example = SELECT description from cpProducts where category='39 47 48 172' I'll assume that your table has a field named 'category' - otherwise the statement should throw you a big error :-) BUT is it a character data field (i.e. does it contain text)? AND do you actually have rows where the value of the category field is '39 47 48 172' - in order to get rows returned when running your example query the value needs to match this string EXACTLY. Given the fact that using mysql control center give you the desired result the above probably was a waste of time typing. Given that fact the only thing I can think of is that you have a extra space floating about (but I can't see it in the code your provided) does the output of mysql_error() provide any feedback? (what an odd problem!) When I run the same query in MYSQL Control center or Query Browser, no problem. I use this function template for my SELECT statements. Please let me know if there is something missing from the code. Thanks. Jason Walker [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] http://www.desktophero.com No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.298 / Virus Database: 265.6.8 - Release Date: 1/3/2005 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP query to mysql database returns emtpy data, butQuery Browser shows records
jwalker wrote: No the category field is varchar(250) and uses spaces to parse each element within the field. The database is an osCommerce hybrid - not my own. The values within the category field go from one number to an X set of numbers, separated by spaces. This is making development rather difficult and painful. Jason, I thought it was something like that - sounds nasty, you poor man! anyway can you confirm that the value in your where clause (as given in your example query) actually exists in the DB. also things to try maybe: 1. test the problem on another machine 2. update php to latest release of you version (probably php4) 3. cut and paste a known value from the category field out of the DB and perform the query again with this value pasted into the query literally (rather than building the value from the various vars) to confirm the problem. good luck ... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] str_replace question
Norland, Martin wrote: -Original Message- From: Bastien Koert [mailto:[EMAIL PROTECTED] Sent: Thursday, January 06, 2005 8:34 AM Subject: Re: [PHP-DB] str_replace question [snip] A neat little trick would be to create the initial part of the statement with a predefined where clause based on some record state. For instance, we use a record_deleted field, since we don't delete data. He could start his statement by automatically looking for it select * from tablename where record_deleted = 'No' then any additional clauses that get added all require the AND keyword. No more problem bastien Alternatively, as mentioned before - something that evaluates to true. The Answer**: select * from tablename where 42 ** to Life, the Universe, and Everything. your killing me, Martin! :-) - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] str_replace question
Brent Baisley wrote: I can't think of an instance where a query would have the phrase WHERE AND. Perhaps if you post the contents of the $additionalsql variable, we can tell you why it's not working. You may actually be looking to use an array tried to explain that to him already, either he ignored it or its too complex - can't say because he never responded. for your search words in str_replace(), or perhaps grep. On Jan 5, 2005, at 8:05 PM, Chris Payne wrote: Hi there everyone, Im having a weird problem and Im not sure why, if I try to replace WHERE AND with just WHERE it wont do it, but if I try to replace WHERE or AND by themselves it WILL do it, but I cannot replace BOTH of them from a single string, is something wrong below? $additionalsql = str_replace(WHERE AND, WHERE, $additionalsql); Basically Im trying to replace WHERE AND with just WHERE as Im building a very complex SQL query and its a difficult one, and I have a solution that works perfectly but I need this to work in order to do it. I would appreciate any help on this, as its very important. Chris -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 12/30/2004 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] terminates string?
Perry, Matthew (Fire Marshal's Office) wrote: I am using PHP 4.3.1 and running Apache Server and MySQL. The following question is probably only related to PHP. Here is the problem: I am passing the following string from one form to another: ../create.php?dest=Employee/menu_handleemployee.php?action=updateID=$ID Here is the actual code: form action=../create.php?dest=Employee/menu_handleemployee.php?action=updateID =?echo $ID;? method=post enctype=multipart/form-data name=form1EMPLOYEE When I view the source it comes out as expected: form action=../create.php?dest=Employee/menu_handleemployee.php?action=updateID =82 method=post enctype=multipart/form-data name=formEMPLOYEE But after it goes to the next page it turns into this: ../create.php?dest=Employee/menu_handleemployee.php?action=update Everything up to and after the '' disappears!! that because PHP sees your URL as having two GET vars: dest=Employee/menu_handleemployee.php?action=update ID=82 the ampersand is the default name/value pair seperator. try using urlencode() [and urldecode() when you actually want to redirect to that 'dest' url] on the redirect string when passing it along in the URL (or form field) e.g. $action = '../create.php?dest='.urlencode(Employee/menu_handleemployee.php?action=updateID=$ID); and if that doesn't work try replacing the '' char with something else e.g. $action = '../create.php?dest='.str_replace('','$$',Employee/menu_handleemployee.php?action=updateID=$ID); and then before your redirect to that url reverse the replacement e.g.: header('location: ' . str_replace('$$','',Employee/menu_handleemployee.php?action=updateID=$ID)); exit; BTW: 2 dollar signs may not be the best choice of chars to use. another way of tackling the issue is by looking at the contents of $_SERVER (a auto superglobal var, just like $_GET, $_POST etc) - try: print_r($_SERVER); you'll be surprised what kinds of useful items are contained in that array. while you're at it try: print_r($_GET); looking at the output of that will probably help you understand where the 'ID' bit of the redirect url went. RANT print_r() is your friend USE IT!!! OFTEN!!! sing this as a reminder When in doubt print it out [ (tm) Wong Coding Industries ;-) ] /RANT The goal of this code is to send the redirect address to the form that modifies my data. I want variable dest to be used to dynamically redirect the page. I have tried the following to fix the problem without avail: 1) I tried saving the variable in other ways such as text fields in the form itself. 2) I tried addslashes() (which works well with similar problems related to ', etc.). 3) I tried adding \ before 4) I danced around my computer and threatened to pull the plug. you forgot to wave the dead chicken around your head! None of these worked! What is it about '' that throws everything off with PHP variables? It doesn't seem to be a problem with HTML. its the default request name/value pair seperator. This is exceedingly difficult to research online because '' is excluded from most search engines automatically. it's called an ampersand. which might help further searching. -Matthew -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Stopping display of DB errors
Todd Cary wrote: When I run a query using Interbase and if an error occurs, the error displays in the browser window even though I am testing for errors. Is there a way to prevent this? function db_insert_logon_session($dbh, $sessionid, $offset) { $fulldate = date(m/d/Y H:i:s,time() + $offset); $stmnt = INSERT INTO SESSION (SES_ID, SES_EXPIRE) . VALUES( . $sessionid . , . ' . $fulldate . '); //echo('Query: ' . $stmnt . 'br'); OK Todd, listen the fuck up :-) you are missing one of the greatest things about the interbase extension, parameterized queries, try doing it like this: $fulldate = date(m/d/Y H:i:s,time() + $offset); $stmnt = 'INSERT INTO SESSION (SES_ID, SES_EXPIRE) VALUES(?,?)' $sthdl = @ibase_query($stmnt,$dbh, array($sessionid,$fulldate)); do it like that and you have just made SQL injection hacks an impossiblity :-), and stray quotes in text strings being entered into the DB will never again break your queries. suck on that MySQL. $sthdl = ibase_query($stmnt,$dbh); -- displays error regardless $sthdl = @ibase_query($stmnt,$dbh); -- shouldnt displays error if ($sthdl) ibase_commit(); else print(Error: . ibase_errmsg() . br); return $sthdl; }; BTW: the interbase extension was rewritten for PHP5, I don't know whether this was backported to PHP4 - the guy that did it is a friend of mine though so I'll ask about that - anyway the reason that I mention this is is that I don't have your problem and I use PHP5 for my firebird/php (the interbase extension is also used for firebird) having said that I have a custom DB class for interbase/firebird which uses the following construction: $res = call_user_func_array('ibase_query', array_values($args)); this is to do with parameterized queries (the number of args is obviously variable). for anyone who reads this far know this: Todd is a superior human being cos he uses a superior DB ;-) MySQL is a single-celled organism next to the space-faring superbeing that is firebird (ok interbase too, but that aint open source) (flame on baby!) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Auto PK
Andrew Kreps wrote: ... 20050105-1 20050105-2 20050106-1 ...etc. This would be a great place for a stored procedure, but I don't know if I can recommend running MySQL 5 to you. The most platform-safe way an open source alternative that does offer this enterprise level functionality (stored procedures) is firebird. and its based on proven tech. (interbase), not to mention its not bleeding edge (firebird stayed in beta so long that if it had been a microsoft product it would have gone gold, shipped, and been put to pasture ;-). but firebird is a little more difficult to get into than MySQL and you may not have access to hosting that provides it. I can think of is to get a count(*) of the number of rows with today's date, add 1 to it, and stick that number on the end of the string you've created to insert into a varchar field. It's an extra query per insert, but it'd do the job. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Warnings and Notices
Jason Davis wrote: I just got the software I was fighting with working. Only issue now is that the top of the page is filled with notices and warnings, even though the code is working. Is there any way to turn off or hide these notifications? read them and fix your code is one way. another is to turn down error reporting: http://nl2.php.net/error_reporting Jason -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Trying to connext to MySQL with PEAR
Ford, Mike wrote: To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm On 06 January 2005 16:39, Jochem Maas wrote: Hutchins, Richard wrote: echo $dsn; $isPersistant = TRUE; doesn't effect the code but 'Persistant' is spelled 'Persistent' Oh dear, as a fully-paid-up pedant, I'm afriad I can't resist this one: Doesn't affect the answer, but this occurrence of 'effect' should be 'affect'. ;) DOH! :-) Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] I'm trying to out perform Martin Norland....
in terms of helpfulness and volume of replies to Q's on this list ;-) but it doesn't help that my mails seem to take hours to reach the list (Martin's keep beating mine to show up). is the list-server against me? or do others also see loads of lag? rgds, Jochem PS - as an even bigger kick in the face - I had the term 'o f f t o p i c' (without the spaces) and the list bounced my message: php-db@lists.php.net: host pair1.php.net[216.92.131.4] said: 550 Apparent off-topic email rejected. (in reply to end of DATA command) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] $_GET of array variables
in the script that recieve the form submission try adding the following lines to view the contents of the $_GET superglobal array. echo 'pre'; print_r( $_GET ); echo '/pre'; once you see the structure it should be clear what array index key(s) you should be using to get to the relevant values. PS - Matt M.'s syntax suggestion is along the right lines (although the actual keys you use may be different. Matt M. wrote: $_GET['simplevariable'] but am not having much luck with anything like: $_GET[arrayvariable$a] (1-dimensional array) or $_GET[arrayvariable$a$b] (2-dimensional array) (I've tried several other odd syntaxes such as $_GET[arrayvariable[$a][$b]]. Also it's not an \ situation.) have you tried $_GET[arrayvariable][$a] or $_GET[arrayvariable][$a][$b] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Display records on form
I'm resending this email as it does seems to have made its way onto the list (as far as I can see) - apologies if this is a double post. anyone else interested in recieving the pagination function I mention below can mail me offlist. here is the original reply: David Ziggy Lubowa wrote: first of all , let me apologize for the top post, second let me apologize for not giving more detail. The main problem is basically pagination , i have failed to add pagination code to my own code simply because it is not as simple as i thought. Considering i am a begginer in PHP , i must give myself some credit for reaching where i am , as for code snippet here goes, ... pagination is fairly simple once you have done it a few times, It took me ages to get my head round too. $link = mysql_connect(localhost, me,me2); mysql_select_db(ip, $link); $qry = mysql_query(SELECT * FROM IP_Addresses where free like '%. $_GET['q'].%', $link); I think you should use the $trimmed var here iso $_GET['q'], also you should make sure that any single quotes in this string are escaped properly (otherwise they will break your query). to do pagination you have to combine pagination links (that are used to propigate the 'page number' and current query parameter) by adding: LIMIT $i, 50 to the end of your query, where $i is a multiple of 50 (lets assume you wish to show 50 rows per page) - $i would be equal to zero for the first page. the value of $i has to be propigated through the pagination links - the function I sent to you offlist has a parameter to handle this. BTW the function I sent you returns HTML (links!) which you need to include with your output to allow users to select different pages. Also note that the second argument to the function is not actually used - its merely there so that the function is also usable as a Smarty plugin. other than using the output from the function I sent you and making use of LIMIT clause the rest of you code does not need to change. TIP: try to seperate processing logic from your output, i.e. breaking in and out of PHP the whole time (using ?php ?) makes you code hard to read/maintain. to start with you could create all ness. vars containing dynamic content at the top of your script and then at the bottom output the HTML (maybe even by including a file, that file would contain just the HTML and enough PHP to output the dynamic data, the file would assume all ness. data vars are set). ? table border=1 width=100%tr?php if (mysql_num_rows($qry)==0 ) { print Oops No records found ; ? br a href=http://localhost/ipsearch2.html;Back/a /br ? exit(); } if (mysql_num_rows($qry) 0) { for ($i = 0; $imysql_num_fields($qry); $i++) { echo td align=centerstrong . mysql_field_name($qry, $i) . /td; } } good for you for taking the generic route rather than hard coding you fieldnames! ? /tr?php if (mysql_num_rows($qry) 0) { for ($j = 0; $jmysql_num_rows($qry); $j++) { ?tr?php for ($k = 0; $kmysql_num_fields($qry); $k++) { echo td align=center . mysql_result($qry,$j, $k) . /td; } ?/tr?php } } ? /table br br a href=http://localhost/index.html;Main Page/a br br a href=http://localhost/ipsearch2.html;IP Address Search/a/br/br /br /br /body /html [/snip] i had posted some time back that i have problems with pagination and got alot of help , but the problem is i have never known how to put the code together with what i have .. any help is appreciated... cheers ... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL Auto PK
OOzy Pal wrote: Dears, Is it possible to have mysql at an ID as 20050105-1 as (MMDD-1), -2, etc. probably, possibly, maybe. take your pick. as Martin Norland already pointed out to someone else; this is not [EMAIL PROTECTED] (that beauty of a comment is forever burned into my neo-cortex! :-) i.e. try a little more info... OOzy = Regards, OOzy What is the purpose of life? __ Do you Yahoo!? Yahoo! Mail - now with 250MB free storage. Learn more. http://info.mail.yahoo.com/mail_250 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] $_GET of array variables
Jochem Maas wrote: in the script that recieve the form submission try adding the following lines to view the contents of the $_GET superglobal array. echo 'pre'; print_r( $_GET ); tip for those pulling their hair out: PRINT_R() is your friend!!! ...sometimes referred to as the poormans debugger. now lets sing together: If in doubt print it out! :-) echo '/pre'; once you see the structure it should be clear what array index key(s) you should be using to get to the relevant values. PS - Matt M.'s syntax suggestion is along the right lines (although the actual keys you use may be different. Matt M. wrote: $_GET['simplevariable'] but am not having much luck with anything like: $_GET[arrayvariable$a] (1-dimensional array) or $_GET[arrayvariable$a$b] (2-dimensional array) (I've tried several other odd syntaxes such as $_GET[arrayvariable[$a][$b]]. Also it's not an \ situation.) have you tried $_GET[arrayvariable][$a] or $_GET[arrayvariable][$a][$b] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL database converter ?
Nayyar Ahmed wrote: Hello All: Is there any tool available for conversion of M$ Access, Oracle etc Databases to MySQL database ? google will probably give you more answers than this list (try also searching for the term 'datapump' and variations on it) IBExpert is one tool that will allow you to reverse engineer an existing DB and then use the model that is created to generate SQL to create a new DB in the format of your choice (the 3 you mention are supported) also bare in mind that not all features of each database can be translated to the others. TIA: -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Removing first word from a string?
Chris, I'll try to explain the basics of a technique I often use: imagine you have 0 or more possible where clauses. start of with an empty array e.g. $whereClauses = array(); now for each clause you need add the relevant subclause as a seperate item to the array (DO NOT include the AND or WHERE string). e.g. if ($foo) { // it up to you to make sure $foo is okay for adding to a query string $whereClauses[] = foofield='$foo'; } once you have gone thru all the possible subclauses that could exist do something like this (I'll assume $sql contains the base query): if (count($whereClauses)) { // we have a where statement to make $sql = $sql . ' WHERE ' . join(' AND ', $whereClauses); } I leave it up to your imagination how you apply this idea! greets, Jochem Bastien Koert wrote: one simple trick is to use a clause that always evaluates correctly. For example, in my site I don't delete data, but flag it with a field (record_deleted) which defaults to 'No' (actually 0) and can be set to 'Yes' (again 1) so that all queries are built with the requirement to use AND ie $sql = select * from tablename where record_deleted = 0 //code to delevop additional where paramters goes here if (!empty($_POST['city'])){ $sql .= AND city like '{$_POST['city']}%' ; }//end if you could also use the same mechanism that PHPMYAdmin does which is to 1 select * from tablename where 1 since one always evaluates to true and does not affect the query, its a simple way of doing the same as above bastien From: Chris Payne [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Removing first word from a string? Date: Mon, 3 Jan 2005 21:46:03 -0500 Hi there everyone, I am building a dynamic MySQL query for a project I am working on, but there are instances where it products WHERE AND instead of WHERE city etc .. due to the nature of the system I am developing. My question is, how can I remove the FIRST AND from a string if it is present, but leave all other AND statements in the string? I would really appreciate any help on this. I can do a find and replace on a string no problem, but just want it to be removed IF it is the FIRST word in the string. Oh and Happy New Year everyone. Chris -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 12/30/2004 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Display records on form
David Ziggy Lubowa wrote: On Tuesday 04 January 2005 10:10, David Ziggy Lubowa wrote: Hey guys , I was wondering , i have 16 records within a table in my Database , i have managed to have a form which can add and modify the records. My only problem is how i can display on a form when i search. Can someone give me heads up on how i can code this in php, to display the records in a tabular manner when i search. how does somebody manage to create a working script to insert/update data in a table and not be able to figure out how to output a simple HTML table listing the current records? I mean, do you want us to teach you how to write PHP? (My rate is 40euros/hour) -- Sorry David but your email shows little to no effort on your part to: a, define you problem succinctly b, show context (e.g. code,SQL snippets) c, show that you have made a decent effort to work the problem. given those facts you can consider yourself lucky to recieve any replies at all. ANYWAY... seeing as I'm bitchin' at ya I might as well give you a small clue the process, roughly speaking is: 1. do a SQL select query. (e.g. SELECT id,name FROM mytable) 2. loop thru the result, for each row output some HTML for a table row e.g. echo ' tr tda href=/edit.php?id='.$row['id'].'edit/td td'.$row['id'].'/td td'.$row['name'].'/td /tr' 3. don't forget to add begin- and ending TABLE tags. try googling 'display a MYSQL result set with PHP': I came up with: http://juicystudio.com/tutorial/php/mysql.asp (which is pretty funny cos the guy wrote a tutorial on mysql/php on an ASP based site!!) sorry i meant 16 fields not records : ) whether you tables has 16 rows or fields seems to me to be completely irrelevant. Any help is highly appreciated. cheers -Z -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] NULL VALUE
first off it would help if you specified what DB you are using and if you are using a DB abstraction lib like PEAR::DB or something similar. also have you tried running these lines directly in a cmdline sql client? is the status column variable width? if not then the value may be 'Active ' (number of padded spaces dependent on length of the field) instead of 'Active'. LightBulbMoment (tm): 5 seconds of searching on the MYSQL site tells me STATUS is a keyword. try either renaming your field or using backticks to escape the name e.g.: $query = 'UPDATE EMPLOYEE SET `STATUS`=\'Inactive\' where `STATUS` IS NULL'; I'm willing to bet you haven't bother to: a. RT(F)M. b. check the errors returned. Perry, Matthew (Fire Marshal's Office) wrote: My status column in my Employee table should have two values Active and Inactive. Right now all the active employees have the value Active and the rest have a NULL value. Why is it that the following commands do nothing? UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS != 'Active'; UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS 'Active'; these should work - expect for the STATUS keyword issue. UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS IS NULL'; this one has a typo (extra ' at the end) UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS = ''; UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS = NULL; these 2 shouldn't work at all. - Matthew -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] NULL VALUE
Norland, Martin wrote: -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Monday, January 03, 2005 12:16 PM Subject: Re: [PHP-DB] NULL VALUE LightBulbMoment (tm): 5 seconds of searching on the MYSQL site tells me STATUS is a keyword. try either renaming your field or using backticks to escape the name e.g.: http://dev.mysql.com/doc/mysql/en/Reserved_words.html doesn't list status, although I am familiar with its various forms e.g. show status. I didn't even go as far looking there I made the assumption that mysql was crapping out on 'STATUS' because of its use in 'SHOW STATUS' query (and the like) - also its hard to determine whats going wrong with someones setup when you have no idea what version of stuff they are running - bare in mind we assume the chap (Matthew Perry) in question is using MySQL but he did not state this so that may be incorrect. at any rate dumping the output of mysql_error() or mysqli_error() would probably have saved him an email to this list. ;-) You're probably right, but I don't exactly see this as a 'clearly documented'. Still, backticking all field names is a good idea anyway. I didn't mean to say it was clearly documented (IMHO reading understanding documentation is one of the hardest parts of programming!) but it took me exactly 5 seconds to determine with a 95% certainty that 'STATUS' was causing his query to crap out. HINT TO 'BEGINNERS': 1. give background to your problem. (context, software versions etc) 2. show that you have taken the time to research it. 3. google on how to successfully pose a question on a mailing list - there are a number of very explicit essays on the subject! 4. don't give up, we have all struggled for hours/days/weeks on the tiniest of problems. 5. don't assume somebody will do it for you if you can't be bothered! 6. expect the occasional RTFM, even when you're doing everything right ;-) Builds character. :-) Cheers, - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] NULL VALUE
Hi Matthew, there are some more comments below but just for the record could you confirm that you are retrieving one or more rows when you issue the following SQL: SELECT * FROM `employee` WHERE `status` IS NULL; if you are getting no rows back then the obviously updating based on the status field being NULL will update nothing. Perry, Matthew (Fire Marshal's Office) wrote: I apologize for my lack of information concerning this problem and I appreciate the advice for beginners. I also did not mean to post it on this list (If you notice my original message also contained a thank you for a question never asked in this list). I am terribly sorry about this error. well don't be too sorry :-) ... spilt milk and all that! HOWEVER: The question can regardless be addressed in this list since it is not appear to be version or database specific. I am using MySQL 4.1 but have experienced the same problem with MS SQL Server. ok. Don't have any experience with MSSQL. (and I'm more of a firebird/interbase kinda guy these days) The issue here is NOT whether STATUS is a keyword. Yes STATUS is a keyword and indeed it would probably be wise if I did not use keywords as column names. The reason I chose to leave this column named STATUS is that it is linked to other databases (ouch!) and such attempts have proven to cause even more problems. ouch indeed. But in theory this does not matter. One can use keywords as column names in all recent versions of MySQL even though this is unadvised (you have to search the MySQL site for longer than 5 seconds to learn this). The problem ;-) you are correct in this, although I would never ever use keywords as column names without quoting (i.e. backticks in MySQL) those names in all queries (even if it does work without quotes on certains versions/dbs/platforms/etc) exists for all column names. I have experimented with other test tables with more standard column names and have had the same result. mysql_error() or mysqli_error() also do not help here. Even if you enter the SQL command directly it posts a result that changes 0 rows and the query completes without any errors. I believe this problem lies in how SQL handles NULL values. Let me change lets be clear here: SQL in a generic term, there are various ANSI standards that define the SQL specifications BUT no one implementation full supports any standard - the handling of the NULL value is DB dependent (that is to say there will be probably inconsistencies) [the great thing about standard is there are so many to choose from ;-)] the column name to avoid the question concerning STATUS as a keyword. UPDATE EMPLOYEE SET STATUS_lsdkrjg='Inactive' where STATUS != 'Active'; UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS 'Active'; UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS IS NULL'; UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS = ''; UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS = NULL; None of these work to update table Employee. that does not surprise me, only half of the 'STATUS' fieldnames in those queries have had their names changed According to some of my SQL reference manuals they should! I have tried the following and had success with one of these options: create table TEST ( testA varchar(30), testB varchar(30) ); insert into TEST values ('a', 'a'); insert into TEST values (NULL, 'a'); +++ | testA | testB | +++ | a | a | | [NULL] | a | +++ UPDATE TEST set testA='b' where testA=''; UPDATE TEST set testA='b' where testA'a'; +++ | testA | testB | +++ | a | a | | [NULL] | a | +++ Finally I tried this: UPDATE TEST set testA='b' where testA IS NULL; this last statement is the proper way of doing it. +++ | testA | testB | +++ | a | a | | b | a | +++ But the last example does not work for ANY fields in my EMPLOYEES table. I thought at first the problem might have arisen with the fact that this table is linked to other databases, but even after I removed the links this problem exists! I think the problem still lies with my understanding of NULL. you should realise that you can never do something like: SELECT * FROM mytable WHERE myfield=NULL the reason being that the NULL value is akin to 'unknown' and having an unknown value be equal to another unknown value is rather illogical (at least that how the gurus of old decided we should live - if you catch my drift) in short NULL is not equal to anything at all, ever - NULL is not even equal to NULL. What am I forgetting about the nature of NULL values? Why won't the following work for NULL values? UPDATE TEST set testA='b' where testA=''; NULL is not equal to an empty string. see above. also check out the searchable online version of the manual at mysql.com where they (try to) explain this in alot more