Wednesday, April 30, 2014

Installing PHPUnit On Windows

I wanted to start contributing to the WordPress unit tests so I needed to install PHPUnit. Turned out it was harder than it might seem (I had a tough time getting it all working) so I thought I’d blog what finally ended up working for me to help save some people some time.
Assuming you already have PHP and MySQL installed, here’s the steps you need to take:
  1. Install PEAR, a dependency for PHPUnit:
    1. Visit http://pear.php.net/go-pear.phar in your browser and save the file into your PHP directory. This is the folder where you can find php.exe.
    2. Open an administrator command prompt. On Vista or Windows 7, hit your Windows key, type “cmd”, right-click the resulting “cmd.exe” search result, and select “Run as administrator”. Navigate to the folder where you have PHP installed, the same folder where you saved the file in the previous step.
    3. Type the following command to execute the file you just downloaded: php go-pear.phar
    4. After a moment, you should start being prompted for some things. The installer is pretty self-explanatory and I think you want a system installation rather than a local one.
    5. Open the folder where PHP is installed and double-click the PEAR_ENV.reg file that has been created. This allows you to run the pear command from any folder.
    6. Verify PEAR is working by running the command pear version
  2. Install PHPUnit:
    1. Turn on auto_discover in PEAR by typing the following command at the command line: pear config-set auto_discover 1
    2. Download and install PHPUnit by running the following command: pear install pear.phpunit.de/PHPUnit
    3. In order to be able to run the phpunit command from any folder, you need to add it to your Windows Path value. Right-click My Computer → Properties → Advanced system settings → Environmental Variables → select “Path” under “System Variables” → Edit → Add a semi-colon (;) and then the full path to your PHP folder onto the end of the value, for example like this: ;D:\Webserver\php
    4. Verify PHPUnit is working by running the command phpunit --version
  3. Set up the WordPress unit tests by following the rest of the steps on the WordPress Core Contributor Handbook now that you have PHPUnit installed.
Done!

Monday, January 13, 2014

Simple PHP PDO Class Implementation

Simple PHP PDO Class Implementation

$host = "127.0.0.1";
$db = "sample";
$username = "root";
$password = "";

$database = new PDO("mysql:host=" . $host . ";dbname=" . $db, $username, $password);

function find_user($username) {
 global $database;
 $p = $database->prepare("SELECT * FROM member WHERE username = ?");
 $p->execute(array($username));
 return $p->fetchObject();
}

$results = find_user("admin");
var_dump($results);

Out put of this function will be like bellow.
object(stdClass)[3]
  public 'id' => string '4' (length=1)
  public 'username' => string 'admin' (length=5)
  public 'password' => string '240824aa0487bca3bdd4deb847954b76' (length=32)
  public 'email' => string 'bthssssiban@gmail.com' (length=17)
  public 'postcode' => string 'Q2Z23S' (length=6)
  public 'status' => string 'Inactive' (length=8)
  public 'code' => string '4172f3101212a2009c74b547b6ddf935' (length=32)
  public '_date' => string '2011-02-17' (length=10)


echo $results->username; will prints the output of the username of value from the database.

Friday, January 10, 2014

Create htaccess folder password with htpasswd

Create htaccess folder password with htpasswd

Lets create the .htaccess file first

<IfModule mod_rewrite.c>
RewriteEngine off
</IfModule>
AuthName "Are You Real User"
AuthType Basic
AuthUserFile "/home/apweb/www/yourfolder/xo/.htpasswd"
require valid-user

Now we create the .htpasswd file, we have to generate the password so it will look like this

root:$apr1$2mMeQzaz$577FZ5p/E8EpdrsoVWFRg0

Please use the following URL to generate the username and the password



Finally copy and paste the generated code to your .htpasswd file and uplaod in to the server
Good Luck!