Re: [PHP-DB] Connecting PHP to MySQL on Windows
On Thu, Jan 6, 2011 at 01:13, michael manning michaelgmann...@gmail.com wrote: Hi, I have installed MySQL 5.1.52, Apache 2.2.15 and PHP 5.3.2 on my Windows Vista computer. The MySQL works fine with the command line client and I have tested the Apache and PHP and it appears fine when I test this with the phpinfo() function. There is just one exception - I cannot connect to a MySQL database from within a PHP script. I have installed the MySQLi extension I know you said MySQL works fine from the CLI, but a stupid question: is the MySQL server running while you're trying to test from PHP? And, if so, on what port does netstat show it running? -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] using PDO vs mysql extension
On Thu, Jan 6, 2011 at 02:52, Miriam Natanzon miriamna...@gmail.com wrote: Hi, I want to build an internal module for common DB-involved tasks: starting with connection, simple queries and go on to multiple pages of results and connecting tables and so on. We are currently working with MySQL but maybe in the future we'll add use of MSSQL (but it's negligible in comparison with the MYSQL percentage of use). I wonder if to base my functions on the abstract layer of PDO or to use mysql function (means mysql_connect and so on). As I see it, mysql functions are more readable and comfortable, but in this case : using MSSQL in the future would affect with new DB module with another implementation. What do would do in such a situation?? You could stick with the native mysql_* and mysqli_* functions, but if you have any hint that your application may eventually change its database platform, or if you at least want the option to easily swap, you should definitely use abstraction. You could use PDO or, as I did, create your own abstraction layers with a common application interface. Then all you need to do is change a configuration variable if you need to switch from, say, MySQL to SQL Server, PostgreSQL, et cetera. The application never notices a difference. For example: ?php define('DB_PLATFORM','mysql'); $db = new DB(DB_PLATFORM); $db-select('*','tablename'); ? There will be some pitfalls and intricacies now and again that require some additional adjustments in the model, but I've found that, for myself, I prefer having full control over the code. Well, that and the fact that it was a specific requirement in the spec of the project. -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] combining the results of mysql query and finding the unique tuples in php
Hi I have a certain number of mysql tables(relation), say 50, some of them having 5 fields and some with 6 fields. a particular search item may be found in multiple tables with multiple rows. I am using a loop to find all those. My problem is I want to first combine all those results and then find all the unique entries. (the query results may overlap). What is the best way to do it? I am trying to make my code as simple as possible: Suppose I have $nRows number of tables; for ($j = 0 ; $j $nRows ; $j++) { $query = select * from .$tables[$j]. where name='xx'; $qRes = mysql_query($query); if (!$qRes) die (Database access failed: . mysql_error()); $numRow = mysql_num_rows($qRes); $numCol = mysql_num_fields($qRes); for ($k = 0 ; $k $numRow ; $k++) { $resRow = mysql_fetch_row($q1Res); echo 'tr'; for ($l = 0; $l$numCol; $l++) { echo td$resRow[$l]/td; } echo/tr; } } This code is printing following values fetched from different table that may be duplicate. I just want the unique rows. chr6 30867310 30867335 1007_s_at 1007_s_at:413:117 chr6 30867423 30867448 1007_s_at 1007_s_at:156:191 chr6 30867492 30867517 1007_s_at 1007_s_at:55:353 chr6 30867543 30867568 1007_s_at 1007_s_at:57:77 chr6 30867550 30867575 1007_s_at 1007_s_at:123:381 chr6 30867556 30867581 1007_s_at 1007_s_at:28:379 chr6 30867563 30867588 1007_s_at 1007_s_at:8:385 chr6 30867569 30867594 1007_s_at 1007_s_at:44:67 chr6 30867595 30867620 1007_s_at 1007_s_at:128:385 chr6 30867692 30867717 1007_s_at 1007_s_at:74:91 chr6 30867765 30867790 1007_s_at 1007_s_at:133:441 chr6 30867772 30867797 1007_s_at 1007_s_at:244:391 chr6 30867778 30867803 1007_s_at 1007_s_at:397:301 chr6 30867786 30867811 1007_s_at 1007_s_at:310:185 chr6 30867851 30867876 1007_s_at 1007_s_at:254:353 chr6 30867858 30867883 1007_s_at 1007_s_at:142:13 chr6 30867310 30867335 1007_s_at 1007_s_at:416:177 chr6 30867423 30867448 1007_s_at 1007_s_at:569:289 chr6 30867492 30867517 1007_s_at 1007_s_at:299:537 chr6 30867543 30867568 1007_s_at 1007_s_at:87:115 chr6 30867550 30867575 1007_s_at 1007_s_at:314:587 chr6 30867556 30867581 1007_s_at 1007_s_at:249:581 chr6 30867563 30867588 1007_s_at 1007_s_at:713:589 chr6 30867569 30867594 1007_s_at 1007_s_at:486:99 chr6 30867595 30867620 1007_s_at 1007_s_at:324:589 chr6 30867692 30867717 1007_s_at 1007_s_at:279:135 chr6 30867765 30867790 1007_s_at 1007_s_at:92:689 chr6 30867772 30867797 1007_s_at 1007_s_at:372:603 chr6 30867778 30867803 1007_s_at 1007_s_at:201:465 chr6 30867786 30867811 1007_s_at 1007_s_at:45:281 chr6 30867851 30867876 1007_s_at 1007_s_at:170:629 chr6 30867858 30867883 1007_s_at 1007_s_at:568:9 chr6 30867310 30867335 1007_s_at 1007_s_at:467:181 chr6 30867423 30867448 1007_s_at 1007_s_at:531:299 chr6 30867492 30867517 1007_s_at 1007_s_at:86:557 - --- Thanks for help -- Fahim Bioinforformatics Lab University of Louisville Louisville, KY - USA
Re: [PHP-DB] Connecting PHP to MySQL on Windows
Hi Daniel, When testing with the CLI, netstat shows: = C:\Users\mmanningnetstat -b Active Connections Proto Local Address Foreign AddressState TCP127.0.0.1:80 mmanning-PC:49391 ESTABLISHED [httpd.exe] TCP127.0.0.1:3306 mmanning-PC:49338 ESTABLISHED [mysqld.exe] TCP127.0.0.1:27015mmanning-PC:49157 ESTABLISHED [AppleMobileDeviceService.exe] TCP127.0.0.1:49157mmanning-PC:27015 ESTABLISHED [iTunesHelper.exe] TCP127.0.0.1:49262mmanning-PC:49263 ESTABLISHED [firefox.exe] TCP127.0.0.1:49263mmanning-PC:49262 ESTABLISHED [firefox.exe] TCP127.0.0.1:49264mmanning-PC:49265 ESTABLISHED [firefox.exe] TCP127.0.0.1:49265mmanning-PC:49264 ESTABLISHED [firefox.exe] TCP127.0.0.1:49338mmanning-PC:3306 ESTABLISHED [mysql.exe] TCP127.0.0.1:49391mmanning-PC:http ESTABLISHED [firefox.exe] TCP130.130.48.79:49208nimmo-37:8080 ESTABLISHED [googletalk.exe] TCP130.130.48.79:49238nimue-37:8080 ESTABLISHED [chrome.exe] TCP130.130.48.79:49344nimue-37:8080 ESTABLISHED [chrome.exe] === I ran the same test script on my computer at home without difficulty. It is running Apache 2.2.16, PHP 5.3.3 and MySQL 5.1.51 on Windows XP Professional SP3. regards Mike michaelgmann...@gmail.com On Fri, Jan 7, 2011 at 3:49 AM, Daniel Brown danbr...@php.net wrote: On Thu, Jan 6, 2011 at 01:13, michael manning michaelgmann...@gmail.com wrote: Hi, I have installed MySQL 5.1.52, Apache 2.2.15 and PHP 5.3.2 on my Windows Vista computer. The MySQL works fine with the command line client and I have tested the Apache and PHP and it appears fine when I test this with the phpinfo() function. There is just one exception - I cannot connect to a MySQL database from within a PHP script. I have installed the MySQLi extension I know you said MySQL works fine from the CLI, but a stupid question: is the MySQL server running while you're trying to test from PHP? And, if so, on what port does netstat show it running? -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/
Re: [PHP-DB] Connecting PHP to MySQL on Windows
Hi, I swapped out 'localhost for '127.0.0.1' in the url but this had no effect. I had a look at my hosts file at c:\windows\system32\drivers\etc and this contained: # Copyright (c) 1993-2006 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host 127.0.0.1 localhost ::1 localhost and so this seems fine as well. cheers Mike On Fri, Jan 7, 2011 at 1:25 PM, Daniel Brown danbr...@php.net wrote: On Thu, Jan 6, 2011 at 21:12, michael manning michaelgmann...@gmail.com wrote: Hi Daniel, When testing with the CLI, netstat shows: [snip!] What happens when you swap out 'localhost' for '127.0.0.1' in the connection routine? If that works, check to make sure your hosts file properly designates 127.0.0.1 as 'localhost' (by editing c:\windows\system32\drivers\etc\hosts I believe been a while since I've done it on Windows). -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/