[PHP] Query result column to array
I'm looking for a native method for taking all of the values from one column of a query result and creating an array of those values. Procedurally, I'd tend to want to do this: query("SELECT my_id FROM my_table"); while ($row = $query_result->fetchRow()) $my_id_array[] = $row['my_id']; ?> Heck, ColdFusion has the ValueList function which does exactly what I want (of course, it returns a delimited list [string], not a native array, but the one-step method is there). Is there anything in PHP-land that does that? Or am I pretty much stuck using some variation of the code above? Christopher Watson Principal Architect The International Variable Star Index (VSX) http://vsx.aavso.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP Access Violations
OK, this is starting to get really annoying. I think it's time I posted this to php-general, and see if there is anything anyone knows about it. For a while now (about two years), I have been developing on a laptop configured as listed below. I'll provide the versions of software I am currently working with, although the problems I will describe have been occurring with regularity over several previous versions of the software. HP Pavilion zx5000 notebook computer 1 GB RAM 120 GB HD Windows XP Pro (SP2) PHP 5.1.6 (running as ISAPI) MySQL Server 5.0.24 SQLyog Enterprise 5.17 The problem became so bad and pervasive that I decided the best thing do (about two week ago) was to wipe this machine completely and rebuild it from the ground up. The main partition was deleted, recreated, slow-formatted, and Windows XP re-installed clean (with ALL updates installed as well). The latest versions of PHP, MySQL, and my client admin program, SQLyog we re-installed. I haven't put much of anything else on this machine, aside from Homesite (to write PHP), and MySQL Administrator to manage users. Process count is low and managed well. There is nothing stupid on this laptop. But the problem persists! Basically, it's an intermittent but frequent "Access Violation" within PHP. It happens at complete unpredictable times. Meaning, I cannot reproduce the problem using a recipe. There are no known sequence of events that cause the problem to occur. After boot, I start developing. I'm running Homesite, writing code, saving it. I'm using IE to run locally the PHP/Fusebox app I have written, using localhost. I have a virtual directory set up in IIS for the app. I test my code, running through several circuits and functions. I use SQLyog Enterprise to make and alter tables, adjust data, perform other analyses through manual queries, etc. etc. Lots of querying going on to the local MySQL server from the app. This is an astronomical data management system, so it is query-heavy. I'm using PEAR::DB and mysqli to do all the PHP/MySQL stuff. My code is two years old and quite robust. It is fully debugged, and I think I write pretty good code that does the right thing. But after a while (again, the time span is unpredictable), things suddenly die. On one request, I won't get back what I'm expecting. Usually a partial page. On the next invocation of PHP, I get an error about an "Access violation" PHP has encountered. At that point, I am dead in the water. PHP simply won't work any more. I have to reboot the system to get it back up and running. This will happen during very single development session. Eventually, after working with Homesite, SQLyog and IE to run and test the app, it WILL die. And it's PHP giving me the error. It seems as if there is nothing I can do to modify my development practices to eliminate or even lessen the frequency of this error. You have to understand that this machine was WIPED CLEAN a couple of weeks ago, and I haven't installed anything on it except the OS and essential development tools. This machine is devoid of any malware, and is extremely process poor. It's a super clean system. Does someone, anyone, has any insight into this? Please help me! Christopher Watson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Access Violations
Hi Wolf, Set up PHP error logging. Proceeded to do some regular development. Created some PHP errors in my code to test logging. Worked great. Expected errors occurred and got logged. Five minutes into the session, wham! This error is what comes up in the browser: "PHP has encountered an Access Violation at 7C911F6C" Dead. I check the error log. Nothing. Not a thing. -Christopher On 9/5/06, Wolf <[EMAIL PROTECTED]> wrote: First thing you need to do is log the boot through the crash of PHP, it sounds like something is getting hung in the processes and crapping out. Personally, I run Apache on windows and Linux machines. It has less tendency to die and gives a great log of when something happens. First step is getting that PHP error/system log. Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Access Violations
Hi Chris, memtest run over several hours, with 2000% coverage. No errors. -Chris On 9/5/06, Chris <[EMAIL PROTECTED]> wrote: Run memtest or something over your machine, sounds more like a hardware issue than anything else. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Access Violations
Thanks for the input, Jon. I'll get to the Apache and IIS restart suggestions soon. Meanwhile, I think I have a semi-repeatable recipe for getting the access violation to happen. As far as I can tell, everything is cool until I open up SQLyog and do some sort of database manipulation within it. Almost immediately after that, switching back to the browser and flying through the app a little more brings on the violation. So far, my testing is indicating to me that the violation does not occur without SQLyog having done some work in the database. -Chris On 9/6/06, Jon Anderson <[EMAIL PROTECTED]> wrote: Christopher Watson wrote: > memtest run over several hours, with 2000% coverage. No errors. My impression of this is that it either has to be a software problem in either PHP or the server (pretty much guaranteed your PHP code should never be allowed to trigger an access violation) or a fundamental hardware issue. In this case, I would first eliminate software problems first - I gather you've used different versions of PHP, so why not try using Apache temporarily and see if that alleviates the problem. Also, what happens after an access violation if you fully stop then restart the IIS service? If you eliminate your web server and PHP as possibilities, I would look to hardware (overheating CPU?), it's obviously not memory. ;-) jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Access Violations
Spoke too soon. After a reboot, I had only IE and Homesite open, making changes to PHP code and running the app, and it hit an access violation. So SQLyog ain't it. -Chris On 9/6/06, Christopher Watson <[EMAIL PROTECTED]> wrote: Thanks for the input, Jon. I'll get to the Apache and IIS restart suggestions soon. Meanwhile, I think I have a semi-repeatable recipe for getting the access violation to happen. As far as I can tell, everything is cool until I open up SQLyog and do some sort of database manipulation within it. Almost immediately after that, switching back to the browser and flying through the app a little more brings on the violation. So far, my testing is indicating to me that the violation does not occur without SQLyog having done some work in the database. -Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Access Violations
Following up on this now... I have successfully installed Apache 2.0.59 (Win32), and configured successfully for PHP 5.1.6 and MySQL 5.0.24. The app is running fine, but I ran a few manipulation queries from the SQLyog interface and Apache did crash. I'll have try to reproduce the problem again in order to get the exception data. This is looking more and more like a SQLyog problem. Maybe I should try another MySQL admin client. -Christopher On 9/6/06, Christopher Watson <[EMAIL PROTECTED]> wrote: Spoke too soon. After a reboot, I had only IE and Homesite open, making changes to PHP code and running the app, and it hit an access violation. So SQLyog ain't it. -Chris On 9/6/06, Christopher Watson <[EMAIL PROTECTED]> wrote: > Thanks for the input, Jon. I'll get to the Apache and IIS restart > suggestions soon. > > Meanwhile, I think I have a semi-repeatable recipe for getting the > access violation to happen. As far as I can tell, everything is cool > until I open up SQLyog and do some sort of database manipulation > within it. Almost immediately after that, switching back to the > browser and flying through the app a little more brings on the > violation. So far, my testing is indicating to me that the violation > does not occur without SQLyog having done some work in the database. > > -Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Access Violations
Hi Wolf, Please correct me if I'm wrong, but neither of these tools from the MySQL team can SSH tunnel. I need that. -Chris On 9/8/06, Wolf <[EMAIL PROTECTED]> wrote: MySQL Query Tool MySQL Admin Tool Both free, both work flawlessly w/ MySQL and both maintained by MySQL Wolf Christopher Watson wrote: > Following up on this now... > > I have successfully installed Apache 2.0.59 (Win32), and configured > successfully for PHP 5.1.6 and MySQL 5.0.24. The app is running fine, > but I ran a few manipulation queries from the SQLyog interface and > Apache did crash. I'll have try to reproduce the problem again in > order to get the exception data. This is looking more and more like a > SQLyog problem. Maybe I should try another MySQL admin client. > > -Christopher > > On 9/6/06, Christopher Watson <[EMAIL PROTECTED]> wrote: >> Spoke too soon. After a reboot, I had only IE and Homesite open, >> making changes to PHP code and running the app, and it hit an access >> violation. So SQLyog ain't it. >> >> -Chris >> >> On 9/6/06, Christopher Watson <[EMAIL PROTECTED]> wrote: >> > Thanks for the input, Jon. I'll get to the Apache and IIS restart >> > suggestions soon. >> > >> > Meanwhile, I think I have a semi-repeatable recipe for getting the >> > access violation to happen. As far as I can tell, everything is cool >> > until I open up SQLyog and do some sort of database manipulation >> > within it. Almost immediately after that, switching back to the >> > browser and flying through the app a little more brings on the >> > violation. So far, my testing is indicating to me that the violation >> > does not occur without SQLyog having done some work in the database. >> > >> > -Chris >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question on explode and join.
Definitely look into preg_match or even preg_replace, instead of tokenizing the string and rubbing it up against an array of your own. Iterate on your array of bad words, and then use Regular Expressions to selectively hunt and squash. You MAY be able to do it in one regex operation by building a search pattern that covers everything. Don't know how much the PCRE functions can swallow at once, but it's worth a try. Christopher Watson Principal Architect The International Variable Star Index (VSX) http://vsx.aavso.org On 9/13/06, Beauford <[EMAIL PROTECTED]> wrote: Hi, I have a form which I want to check for inappropriate words before it is posted. I have used explode to put the string into an array using a space as the delimiter and then I check it against another array that contains the inappropriate words. I then replace the inappropriate words with *'s and join the array back into a string. This works perfectly except for one thing. If the word in the string has a any kind of punctuation after it (period, comma) it won't be matched. So if moron is an inappropriate word then "you are a moron" works, but "you are a moron." won't. Any ideas? Thanks This is my code. function badwords($string) { $language = array(contains the inappropriate words); $words = explode(" ",$string); $count = count(explode(" ", $string)); for($i = 0; $i < $count; $i++) { if(in_array(strtolower($words[$i]), $language)) { $words[$i] = "*"; } } $newcomments = join(" ",$words); return $newcomments; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] stripping with an OB callback
I've been coding with PHP for maybe a year. So I'm somewhat new to it. But I've learned quickly, and created a fairly serious LAMP app that is capable of returning large query results. During my investigation into various means for incrementally reducing the response sizes, I've discovered output buffering with a callback function. So, as an experiment, I bracketed my includes of the Fusebox files in index.php with ob_start('sweeper') and ob_end_flush(), and placed the simple callback function at the top of the file that performs a preg_replace on the buffer to strip all excess space: function sweeper($buffer) { return preg_replace("/\s\s+/", " ", $buffer); } Results? Kinda nice! A large query result measuring over 900K of HTML is reduced to 600K. With no change at the browser. Still valid HTML, and the browser happily gobbles it up and displays it cleanly. It's just 30% faster getting to me. Now, the question. Is this going to bite me in the ass? 'Cause right now, it looks dang good to me. Great bang for the buck, as far as I'm concerned. I've been churning it over in my head, and I don't see a situation (certainly not in my particular app) where doing this whitespace reduction is going to backfire. There isn't anything in any of this that requires the contiguous non-word characters. I have a feeling though, that one of you more learned PHPers are going to tell me exactly where my ass is gonna start hurtin'. Christopher Watson Principal Architect The International Variable Star Index (VSX) http://vsx.aavso.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
Hi Robert, Well, I think the main reason I'm not using transparent output compression is because this app shares php.ini with several other PHP apps on the server, and I don't want to foist this change on the admins of those apps. I was trying to come up with a localized strategy for trimming my app's output. The issue is not an issue for me. -Christopher On 9/20/06, Robert Cummings <[EMAIL PROTECTED]> wrote: Should be an issue as long as you're not stripping whitespace from between tags. Although, one must wonder why you don't just use output compression since all that whitespace would just compress anyways as would all the other content. In fact 900k with fairly standard content would shrink to about 90k. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
Bingo! That's the ticket. Thanks, Robert. -Christopher On 9/20/06, Robert Cummings <[EMAIL PROTECTED]> wrote: Why settle for 30% speed boost when you can get 90% ... http://ca3.php.net/manual/en/function.ob-gzhandler.php :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there a list of all Timezones as an array or someting?
Might also want to have a look-see at the Date_TimeZone class of the PEAR::Date package. It seems pretty comprehensive with regard to time zone coverage. -Christopher -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help converting C to PHP
Definitely looks like a grouping and/or precedence problem. Wish I had more time to examine it. Fine-tooth those parens again. -Christopher -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback [SOLVED]
Thanks for the follow-up Richard. I am now bracketing my Fusebox core includes with ob_start("ob_gzhandler") and ob_end_flush(). It's done wonders for those large query results. And since there is absolutely nothing in this app that relies on multiple contiguous whitespace characters, I'm good to go. Christopher Watson On 9/22/06, Richard Lynch <[EMAIL PROTECTED]> wrote: Cannot compression be set in .htaccess? Or even within the script??? I suspect you could even find a PHP class out there to compress and send the right headers to do it all in PHP, regardless of server settings... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php