[PHP] sorting via PHP or MySQL?
(I've cross posted at the MySQL list as well) Here's an example with a simple table: describe collection; +--+-+--+- +-++ | Field| Type| Null | Key | Default | Extra | +--+-+--+- +-++ | id | bigint(20) unsigned | | PRI | NULL| auto_increment | | receiver_id | bigint(20) unsigned | | MUL | 0 || | set_type_id | int(2) unsigned | | | 0 || | card_id | int(3) unsigned | | | 0 || | completed_set_id | bigint(20) unsigned | | | 0 || | created_on_gmt | datetime| | | -00-00 00:00:00 || +--+-+--+- +-++ I want to end up with two PHP arrays. One for set_type_id = 22 and one for set_type_id=21. (1) one query method: SELECT * from collection WHERE set_type_id=22 OR set_type_id=21; ...do query... while( $row = $this-db-fetch_array_row() ){ if ($row['set_type_id'] == 21){ $array_a[] = $row; } else { $array_b[] = $row; } } (2) two query method: SELECT * from collection WHERE set_type_id=22; ...do query... while( $row = $this-db-fetch_array_row() ){ $array_a[] = $row; } SELECT * from collection WHERE set_type_id=21; ...do query... while( $row = $this-db-fetch_array_row() ){ $array_b[] = $row; } Which method is better? Take a hit using MySQL or take a hit using PHP? -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] finding a particular record within a MySQL result set
I've cross posted this to the MySQL list... Here's my original post. Is there some quick way to do the following in MySQL? (I know I can use PHP to search through the result set, but I wanted to see if there's a quick way using some sort of query) Let's say I know that Joe is from Maine. I want to do a query of all employees from Maine, ordered by hiring date, and figure out where Joe falls in that list. (i.e. which record number is he?) -James Here's my new plan of attack... Right now I'm trying to use PHP to do a binary search on the result set so I don't have to traverse the entire result set. I'm using PHP's mysql_data_seek() to move the pointer within the result set and looking at the data to do the necessary comparisons. What do people think of this approach? -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] finding a particular record within a MySQL result set
I've looked at those, but both approaches requires traversing through the entire mysql result set to create another array ( could be memory intensive if the result set is large...100,000 ? ) -James On Apr 4, 2007, at 1:39 PM, Jim Moseby wrote: You will probably get a better approach from the mysql list, but from a PHP solution perspective, I'd load up an array with the result set and use key() to get the number. The example at http://php.net/key does exactly that. Or array_search() :) JM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] reversing utf-8 string
There doesn't seem to be a multibyte equivalent of strrev(). Is there an easy way to reverse the order of characters in a string w/o traversing the characters backwards and creating a new string by concatenating the characters? -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] backing up a database
Does one need to lock(?) MySQL before running mysqldump? Or will the mysqldump command wait for any pending operations to finish, lock the tables for dumping and once finished release the lock? -James On Nov 27, 2006, at 2:21 AM, David Robley wrote: Sumeet wrote: Brad Fuller wrote: $command = mysqldump -u $dbuser -p$dbpass $dbname | gzip $backupFile; system($command); what if system() has been disabled on the server? SELECT INTO OUTFILE 'file_name' export_options seems a useful alternative. Cheers -- David Robley I haven't caught a fish all day! Tom said, without debate. Today is Sweetmorn, the 39th day of The Aftermath in the YOLD 3172. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] backing up a database
Thanks Brad: I'm just surprised that when people mention mysqldump, most of the time they don't talk about locking the tables at all. I'm curious why this is the case. -James Does one need to lock(?) MySQL before running mysqldump? Or will the mysqldump command wait for any pending operations to finish, lock the tables for dumping and once finished release the lock? -James It is my understanding that mysql will not do this unless specified. http://dev.mysql.com/doc/refman/4.1/en/mysqldump.html --lock-all-tables, -x Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole dump. This option automatically turns off --single-transaction and --lock-tables. Added in MySQL 4.1.8. --lock-tables, -l Lock all tables before dumping them. The tables are locked with READ LOCAL to allow concurrent inserts in the case of MyISAM tables. For transactional tables such as InnoDB and BDB, --single-transaction is a much better option, because it does not need to lock the tables at all. Please note that when dumping multiple databases, --lock-tables locks tables for each database separately. Therefore, this option does not guarantee that the tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states. -B -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
$arr = array(...); $first_row = ''; $second_row = ''; for ($i=4; $i=0; $i--){ $first_row = $first_row . td{$arr[$x]}/td; $second_row = $second_row . td{$arr[$x + 5]}/td; } print 'tr' . $first_row . '/tr'; print 'tr' . $second_row . '/tr'; On Nov 16, 2006, at 3:19 PM, Ashley M. Kirchner wrote: Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php cli and mysql
I'm running a php script from the command line (I'm on OS X) and I'm getting ... Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) Here's the script (this just tests a connection and a query...the actual script imports data from text files): #!/usr/bin/php ?php echo HELLO WORLD\n; $connection = mysql_connect(HOST, ID, PW); mysql_select_db(DB, $connection); $result = mysql_query(SELECT COUNT(*) as num_of_countries from geo_entities); $row = mysql_fetch_array($result); print_r($row); ? I tested the script from a browser and the connection and query worked. Do I have to do something special in order for PHP CLI to connect to MySQL? -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
ok. so the location of mysql.sock is a problem. I found it at /tmp/mysql.sock Why is the CLI looking for it at /var/myslq/mysql.sock? Now the question is... Do I change the mysql settings so that mysql.sock is at /tmp/ mysql.sock? (If I do, will the PHP module with Apache still be ok?) or Do I change where the CLI is looking for mysql.sock? -James On Nov 14, 2006, at 1:17 PM, cajbecu wrote: touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock On 11/14/06, James Tu [EMAIL PROTECTED] wrote: I'm running a php script from the command line (I'm on OS X) and I'm getting ... Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) Here's the script (this just tests a connection and a query...the actual script imports data from text files): #!/usr/bin/php ?php echo HELLO WORLD\n; $connection = mysql_connect(HOST, ID, PW); mysql_select_db(DB, $connection); $result = mysql_query(SELECT COUNT(*) as num_of_countries from geo_entities); $row = mysql_fetch_array($result); print_r($row); ? I tested the script from a browser and the connection and query worked. Do I have to do something special in order for PHP CLI to connect to MySQL? -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
Please see below On Nov 14, 2006, at 2:24 PM, [EMAIL PROTECTED] wrote: Run this command: /path/to/cli/php -i|grep MYSQL_SOCKET MYSQL_SOCKET = /var/mysql/mysql.sock What does that show? It sounds like the PHP module for Apache is using a different php.ini file then the CLI version. I know for a fact that Apache is using: /usr/local/php5/lib/php.ini It also looks like the CLI versions php.ini is not pointing to the proper path to the mysql.sock. Look under the mysql section of your php.ini and fix that up. To see where its pointing, do this: /path/to/cli/php -i|grep php.ini Configuration File (php.ini) Path = /etc but when I looked inside /etc there was no php.ini, but there is a php.ini.default... I could create another here... or should I create a symbolic link to the php.ini that Apache is using? That'll tell you where the php.ini file is for the CLI version. Enjoy. James Tu wrote: ok. so the location of mysql.sock is a problem. I found it at /tmp/mysql.sock Why is the CLI looking for it at /var/myslq/mysql.sock? Now the question is... Do I change the mysql settings so that mysql.sock is at /tmp/mysql.sock? (If I do, will the PHP module with Apache still be ok?) or Do I change where the CLI is looking for mysql.sock? -James On Nov 14, 2006, at 1:17 PM, cajbecu wrote: touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock On 11/14/06, James Tu [EMAIL PROTECTED] wrote: I'm running a php script from the command line (I'm on OS X) and I'm getting ... Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) Here's the script (this just tests a connection and a query...the actual script imports data from text files): #!/usr/bin/php ?php echo HELLO WORLD\n; $connection = mysql_connect(HOST, ID, PW); mysql_select_db(DB, $connection); $result = mysql_query(SELECT COUNT(*) as num_of_countries from geo_entities); $row = mysql_fetch_array($result); print_r($row); ? I tested the script from a browser and the connection and query worked. Do I have to do something special in order for PHP CLI to connect to MySQL? -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
Thanks everyone! On Nov 14, 2006, at 3:20 PM, [EMAIL PROTECTED] wrote: You could make a new php.ini for flexibility like Jochem stated. To make things easy, just copy the file over: cp /usr/local/php5/lib/php.ini /etc/php.ini And that should do it. James Tu wrote: Please see below On Nov 14, 2006, at 2:24 PM, [EMAIL PROTECTED] wrote: Run this command: /path/to/cli/php -i|grep MYSQL_SOCKET MYSQL_SOCKET = /var/mysql/mysql.sock What does that show? It sounds like the PHP module for Apache is using a different php.ini file then the CLI version. I know for a fact that Apache is using: /usr/local/php5/lib/php.ini It also looks like the CLI versions php.ini is not pointing to the proper path to the mysql.sock. Look under the mysql section of your php.ini and fix that up. To see where its pointing, do this: /path/to/cli/php -i|grep php.ini Configuration File (php.ini) Path = /etc but when I looked inside /etc there was no php.ini, but there is a php.ini.default... I could create another here... or should I create a symbolic link to the php.ini that Apache is using? That'll tell you where the php.ini file is for the CLI version. Enjoy. James Tu wrote: ok. so the location of mysql.sock is a problem. I found it at /tmp/mysql.sock Why is the CLI looking for it at /var/myslq/mysql.sock? Now the question is... Do I change the mysql settings so that mysql.sock is at /tmp/mysql.sock? (If I do, will the PHP module with Apache still be ok?) or Do I change where the CLI is looking for mysql.sock? -James On Nov 14, 2006, at 1:17 PM, cajbecu wrote: touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock On 11/14/06, James Tu [EMAIL PROTECTED] wrote: I'm running a php script from the command line (I'm on OS X) and I'm getting ... Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) Here's the script (this just tests a connection and a query...the actual script imports data from text files): #!/usr/bin/php ?php echo HELLO WORLD\n; $connection = mysql_connect(HOST, ID, PW); mysql_select_db(DB, $connection); $result = mysql_query(SELECT COUNT(*) as num_of_countries from geo_entities); $row = mysql_fetch_array($result); print_r($row); ? I tested the script from a browser and the connection and query worked. Do I have to do something special in order for PHP CLI to connect to MySQL? -James --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php.ini and .htaccess not working for php parameters
I've setup a few directories under my dev server's webroot...one for each project. Under each project directory, I put php.ini files to set parameters such as include_path. For some reason they are not taking effect. Do I have to enable them somehow? phpinfo() tells me that Server API is Apache, so that means PHP is running as a module not as CGI right? So php.ini only works with PHP running as CGI? I tried to use an .htaccess file instead and that didn't work either. In my httpd.conf I have set Options All AllowOverride All Before, when I was using php.ini, i was getting an error from my include command...basically saying that it couldn't find the file. Now that I'm using the .htaccess, I don't see any PHP errors, I put some print statements just to see where things go wrong. include ('class.datetime_utility.php'); print hello; //shows up $dd = new datetime_utility(); print hello; //doesn't show up!!! What's happening here? (In the past, I just modified the include_path of the main php.ini and this doesn't seem like a flexible solution. I want to localize the settings in separate php.ini files for each project, so that when I have to deploy to production, I can also deploy the php.ini with minor adjustments.) -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php.ini and .htaccess not working for php parameters
Sorry...it was my own sillyness. After confirming that the .htaccess file was indeed setting the include_path directory, it turns out that the class file was renamed and PHP could not find it. I'm surprised that PHP doesn't complain that it couldn't find the file...then I started to comment out stuff in my .htaccess and it turns out that the culprit for now displaying errors was: php_value error_reporting E_ALL When I commented that out, PHP reported the errors. ugh! Can I set that parameter in .htaccess? -James On Nov 8, 2006, at 5:14 PM, James Tu wrote: I've setup a few directories under my dev server's webroot...one for each project. Under each project directory, I put php.ini files to set parameters such as include_path. For some reason they are not taking effect. Do I have to enable them somehow? phpinfo() tells me that Server API is Apache, so that means PHP is running as a module not as CGI right? So php.ini only works with PHP running as CGI? I tried to use an .htaccess file instead and that didn't work either. In my httpd.conf I have set Options All AllowOverride All Before, when I was using php.ini, i was getting an error from my include command...basically saying that it couldn't find the file. Now that I'm using the .htaccess, I don't see any PHP errors, I put some print statements just to see where things go wrong. include ('class.datetime_utility.php'); print hello; //shows up $dd = new datetime_utility(); print hello; //doesn't show up!!! What's happening here? (In the past, I just modified the include_path of the main php.ini and this doesn't seem like a flexible solution. I want to localize the settings in separate php.ini files for each project, so that when I have to deploy to production, I can also deploy the php.ini with minor adjustments.) -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] list of countries
Does anyone have a list of countries in a handy format for importing into MySQL? I just really need a list. Wikipedia has a nice list, but it's muddled by HTML tags. If you also have them in Chinese and Arabic that would be even better. -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] list of countries
Thanks everyone for the helpful links and suggestions! Any people here with access to a country list in Arabic or Chinese? -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] list of countries
Sorry, maybe I should have posted on that list. My post was about the list rather than about using MySQL. My initial thought was that country lists would have been something that people in this forum would have encountered and was also hoping that some people here would have multi-language experience for country lists in other languages. Thanks to all that have pointed me in the right direction. -James On Nov 7, 2006, at 4:41 PM, Rory Browne wrote: A MySQL list would have been a better place for this. Then again Most people on the MySQL list would have known about http://dev.mysql.com/doc/world-setup/en/world-setup.html where as people on this are less likely to. On 11/7/06, James Tu [EMAIL PROTECTED] wrote: Does anyone have a list of countries in a handy format for importing into MySQL? I just really need a list. Wikipedia has a nice list, but it's muddled by HTML tags. If you also have them in Chinese and Arabic that would be even better. -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Run script every 30 seconds
I've never tried this myself, but how about having the cron job kick off a script which will run script A and script B Script A runs right away, and script B runs after a delay of 30 seconds ( usleep(30* 100) )? -James On Oct 30, 2006, at 12:29 PM, Ahmad Al-Twaijiry wrote: Hi everyone, I have a script that I want it to run every 30 seconds, the problem is that cronjob can run every 1 minute only, do you have any solution ? -- Ahmad http://www.v-tadawul.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Most stable combination of AMP?
Hi: I'm trying to setup a dev environment using Apache, MySQL and PHP...to develop an application that will go to production. What is the most stable versions of the AMP components should I can install? The production environment will most likely live on a Linux machine. My dev environment will be on OS X. Thanks. -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Most stable combination of AMP?
I was thinking more along the lines of what version of Apache, MySQL and PHP I should install... -James On Sep 20, 2006, at 12:06 PM, Pawel Miroslawski wrote: On 9/20/06, Kae Verens [EMAIL PROTECTED] wrote: James Tu wrote: Hi: I'm trying to setup a dev environment using Apache, MySQL and PHP...to develop an application that will go to production. What is the most stable versions of the AMP components should I can install? The production environment will most likely live on a Linux machine. My dev environment will be on OS X. that's a religious question. some people advocate some distributions over others. Personally, I recommend Fedora - it's easy to install, and you can use yum and yumex (graphical yum) for package management. Kae -- Hi I agree it's a religious question. I prefer Debian, apt-get is a really comfortable tool and it install all require dependencies. All procedure LAMP install it only 4 commands ex. apt-get install php5 :) It's a very fast and nice (best what i know). Representant of debian's church ;) Paul * * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] are these db stats normal?
I used phpMyAdmin to look at the stats for this mysql server. http://www.2-bit-toys.com/db_info/server_status.html What concerns me mainly are the stats at the top-right...'Failed attempts' and 'Aborted.' When would these situations occur? Is it normal to see these? I'm using PHP's mysql_pconnect for all my scripts. Could this be causing the failed/aborted attempts? What is not clear is if mysql_pconnect will open another connection if the current one is being used. -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP inside .htacess protected file
I have this dilemma...I know this is more of an apache question than a PHP questions, but I thought that it's partially related. We have a webserver that we want to turn on/off access. We were thinking of using simple HTTP authentication to protect the main webserver directory. We have Flash movies that talk to PHP scripts inside the webserver directory. When we have our .htaccess file inside the main webserver directory, Flash can't comunicate with the PHP scripts. So ideally this is what we want...prevent access to the directory but allow our Flash movies to talk to the PHP scripts in the directory. How would I go about doing this? Can I create a subfolder to put the PHP scripts in and put another .htaccess in that folder to override the protection? Thanks. -- -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] POST variables from a link...and popup new window
Hi: I have a link that, when clicked on, pops up a new window. I want to use the POST method in order to pass information. Right now I'm appending the parameters to the URL of the link and using GET to retrieve the name/value pairs. Is there a way to do this? -- -James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP MYSQL table locking
I understand table locking with MYSQL. My concern is this. What happens if a php script issues a LOCK, and then somehow crashes without issuing an UNLOCK? All other scripts will not be able to access the LOCKed tables. What is the solution for a situation like this? It will be pretty unlikely, but I'm curious if there is anything I can do to mitigate this situation. -- -James Tu --- ESI Design 111 Fifth Avenue 12th floor New York, NY 10003 (212) 989-3993 ext. 357 (212) 673-4061 (fax) --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php