Finding Duplicate Records in MySQL

So I was needed to find some duplicate records in a table that had more than 3,000 records. I stumbled upon this query which made my life easier.

SELECT `field`, COUNT(`field`)
FROM `table`
GROUP BY `field`
HAVING ( COUNT(`field`) > 1 )

MySQL Search and Replace

This is definitely useful…

UPDATE `<table_name>` SET `<field_name>` = replace( <field_name>, ‘<string_search>’, ‘<string_replace>’ ) ;

Cheers!!

Ternary; which means this stuff ? :

OK, I needed to write this down as I do not use this comparison on a daily basis, but use it enough where its getting annoying that I have to research it every time I use it.

So without further ado…..

(expression) ? ‘do this if true‘ : ‘do this if false

Voila

OOP in PHP not the same as Java

We all know that PHP5 has a lot more OOP features than PHP4, and we all know that it is not a real OOP language. There are a lot of things in PHP5 that won’t work like Java (obviously). With that said, I just want to point out one feature that I noticed while playing with PHP5 classes.

In Java, when you extend a class, it will run the parent’s class constructor first, then it will invoke the subclass’s constructor. Unfortunately in PHP5, when you extend a class, it will NOT invoke the parent class. You will have to manually invoke it yourself using the ‘parent::’ construct. Here’s some code (syntax may be wrong, excuse me, but you get the point):

class Hello
{
    public function __construct()
    {
      echo "Hello";
    }
}

class World extends Hello
{
    public function __construct()
    {
        parent::_construct(); //<-- must do that in order for the output to be "Hello World!";
        echo " World!";
    }
}

$test = new World();
?>

Output above would be..
Hello World!

If you didn’t add the parent::__construct(), output would be..
World!

Deny Users in a Directory and Allow Users in Subdirectory

It took me a while to figure this out. I wanted to deny the public access to a directory, like /deny and allow the public in a subdirectory like /deny/allow.

This was done by the specific order of Allow, Deny. If you mix these up, you will either allow all or deny all. Anyway, here’s what you do to deny users to /deny and allow users in /deny/allow.

<Directory /deny>
Order allow,deny
Allow from insert IP's
</Directory>

<Directory /deny/allow>
Order deny,allow
Allow from all
</Directory>

Free DNS Tools??

This is more a rant than anything to do with what I normally post, but I just had to post this!!

In case you don’t know, I am a System Administrator for a web design company and I used to work in Tech Support for a hosting company. Since the beginning, I used dnsstuff.com for all my DNS, domain name, email tests. That site was great up until they require you to register. I was so upset that I purchased my own domain name, dnsyard.com, and started to work on my own “dnsstuff”.

Anyway, I periodically check my google ranking (OK, you got me, more like everyhour!!) and I noticed that I am on page 4 for the keyphrase, “free dns tools” (WOO HOO!!). Of course, dnsstuff ranks number one, but I noticed that the number 2 spot has changed. Well it happened to be freednstools.com. I never noticed them, and I’m sure I would have a while ago, but I decided to check them out.

So I did some snooping around. I checked their source code and first of all, noticed that they weren’t using any Keyword Meta Tags, and they rank 2nd, which doesn’t really bother me because the domain name is pretty much the keyphrase (noticed I didn’t link to them at all in this post? haha). Also, their homepage is exactly how dnsstuff used to be, and it included the same exact tools too. So I did a whois for their domain name on their site. And what do you know… The page returned an error.

Warning: fopen(http://www.dnsstuff.com/tools/whois.ch?ip=freednstools.com) [function.fopen]: failed to open stream: HTTP request failed!

WOW!! I guess that’s one way to compete with dnsstuff.com. What more can I say??

BTW, check out my site,  http://dnsyard.com/ (in case you forgot it). I only have a few tools, but I will continue to add to it. Hope you enjoy it.

Done!!

Error installing GD from php5-extensions using FreeBSD Ports

I’ve run into another problem installing Apache-PHP-MySQL FreeBSD server. While installing php5-extensions, I received an error when it tried to install GD. Here’s the error:

===> Patching for php5-gd-5.2.3
===> Applying FreeBSD patches for php5-gd-5.2.3
===> php5-gd-5.2.3 depends on executable in : phpize - found
===> php5-gd-5.2.3 depends on file: /usr/local/bin/autoconf259 - found
===> php5-gd-5.2.3 depends on file: /usr/local/libdata/xorg/libraries - not found
===> Verifying install for /usr/local/libdata/xorg/libraries in /usr/ports/x11/xorg-libraries
/usr/X11R6 exists, but it is not a symlink. Installation cannot proceed.
This looks like an incompletely removed old version of X. In the current version, /usr/X11R6 must be a symlink if it exists at all.Please read /usr/ports/UPDATING (entry of 20070519) for the procedure to upgrade X.org related ports.
*** Error code 1
Stop in /usr/ports/x11/xorg-libraries.
*** Error code 1

Stop in /usr/ports/graphics/php5-gd.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.

To fix, all I did was add WITHOUT_X11=yes to my make install line. You can also do a XORG_UPGRADE=yes. Either way works, but the latter will install some x11 items.

Done!!

Search Engine Friendly URL’s Using Mod_Rewrite

Want to make http://domain.com/awesomepage.php?page=4&user_id=badass&action=go look like http://domain.com/awesome/page/4/user/baddass/go ?? To do this, you will need to use mod_rewrite in .htaccess or edit your Virtual Host in httpd.conf.

Here is the code:


Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/awesome/page/([0-9]+)/user/(.+)/(.+)$ /awesomepage.php?page=$1&user_id=$2&action=$3 [NC]

Yes, you will need to create more than one entry per page, but if you plan it out correctly, you will need just one.
That’s all there is to it.

Done!!

What’s My IP Address

Since I have a dynamic IP address at home, I always have to look it up whenever I access anything that is IP restricted at work.

All I do is run a simple code:

echo $_SERVER[REMOTE_ADDR]

Or you can check out my other page, http://topherdotcom.com/scribble/what-is-my-ip-address/ to see your own IP address.

Done!!

Can’t Install mysql50-server Through the Ports?

I’ve been trying to install mysql50-server via ports, but have been getting a checksum error, like this:

=> MD5 Checksum mismatch for mysql-5.0.41.tar.gz.
=> SHA256 Checksum mismatch for mysql-5.0.41.tar.gz.
===> Giving up on fetching files: mysql-5.0.41.tar.gz mysql-5.0.41.tar.gz
Make sure the Makefile and distinfo file (/usr/ports/databases/mysql50-server/distinfo)
are up to date. If you are absolutely sure you want to override this
check, type "make NO_CHECKSUM=yes [other args]".
*** Error code 1

Stop in /usr/ports/databases/mysql50-server.
*** Error code 1

Stop in /usr/ports/databases/mysql50-server.

For an easy fix, all I did was fetch the mysql tar from freebsd.org and place in /usr/ports/distfiles/, intalled again through the ports, and voila!!

Here’s an easy one liner fixer (for the lazy people, like me). Just copy and paste at prompt.

cd /usr/ports/distfiles/ && fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/mysql-5.0.41.tar.gz && cd /usr/ports/databases/mysql50-server/ && make install clean

NOTE: This is all one line.

Done!!