Archives for 

PHP

2 Common errors while setting up phpMyAdmin on Mac OSX

You might encounter the following two errors while installing phpMyAdmin on OSX

  • Login without password is forbidden by the configuration ( See AllowNoPassword )
  • #2002 can not login tot the MySQL server

Here are the fixes for the above two errors.

1. Open phpMyAdmin configuration located at (phpMyAdmin Folder)/config.inc.php and change

$cfg['Servers'][$i]['AllowNoPassword'] = False; to $cfg['Servers'][$i]['AllowNoPassword'] = true;

2. In the configuration file change  $cfg['Servers'][$i]['host'] = 'localhost'; to $cfg['Servers'][$i]['host'] = '127.0.0.1';

Trying cakePHP, lets see how it goes.

My growing list of direct AD sales was becoming hard to manage, dealing with direct AD sales was taking more time than it should actually take. It’s not streamlined. I lost AD revenue several times because I was too lazy to mail the advertisers about the renewal of their adspace.

I always wanted to automate the AD sales process, but I was busy with something or the other. Now that I got some free time to explore new stuff, I decided to take up this project.

Goals of the project

  • Maintain a list of advertisers and the AD space they bought.
  • Automatically send reminders to advertisers about renewals.
  • If they fail to renew, notify me, so that I can take down the AD.
  • A web interface where I can add details about the newly bought ads to the DB and make changes to previously bought ADS.
  • *Update the DB automatically when a payment is made through PayPal.
  • *Setup a AD server, which will let me control AD’s on all the sites without from a single location.

I’m going to implement this project using cakePHP, I hope cakePHP is the right choice.

 

Subtracting two dimensional arrays in PHP

In the development a WordPress plugin I had to subtract two dimensional arrays. I tried array_diff() function, unfortunately it doesn’t seem to work for two dimensional arrays. Even if it worked, it wasn’t exactly the functionality I wanted.

Be warned, this isn’t exactly a alternate for array_diff(). For difference of two dimensional arrays you may try this (I dint try it)

I had these two arrays, which I had to subtract.

Array (
 [thumbnail] => Array ( [width] => 150 [height] => 150 [crop] => 1 )
 [medium] => Array ( [width] => 300 [height] => 300 [crop] => )
 [large] => Array ( [width] => 1024 [height] => 1024 [crop] => )
 [full-post-thumb] => Array ( [width] => 576 [height] => 150 [crop] => 1 )
 [popular-posts-home] => Array ( [width] => 210 [height] => 90 [crop] => 1 )
 [popular-posts-widget] => Array ( [width] => 32 [height] => 32 [crop] => 1 )
 [mag1] => Array ( [width] => 170 [height] => 0 [crop] => 1 )
 [mag2] => Array ( [width] => 284 [height] => 0 [crop] => 1 )
 [blog-thumb] => Array ( [width] => 135 [height] => 90 [crop] => 1 )
 [slider1] => Array ( [width] => 250 [height] => 130 [crop] => 1 )
 [slider2] => Array ( [width] => 576 [height] => 280 [crop] => 1 )
)

Array (
 [full-post-thumb] => Array ( [width] => 576 [height] => 150 [crop] => 1 )
 [popular-posts-home] => Array ( [width] => 210 [height] => 90 [crop] => 1 )
 [popular-posts-widget] => Array ( [width] => 32 [height] => 32 [crop] => 1 )
 [mag1] => Array ( [width] => 170 [height] => 0 [crop] => 1 )
 [mag2] => Array ( [width] => 284 [height] => 0 [crop] => 1 )
 [blog-thumb] => Array ( [width] => 135 [height] => 90 [crop] => 1 )
 [slider1] => Array ( [width] => 250 [height] => 130 [crop] => 1 )
 [slider2] => Array ( [width] => 576 [height] => 280 [crop] => 1 )
)

The result I wanted was this, but array_diff() returned null.

Array (
 [thumbnail] => Array ( [width] => 150 [height] => 150 [crop] => 1 )
 [medium] => Array ( [width] => 300 [height] => 300 [crop] => )
 [large] => Array ( [width] => 1024 [height] => 1024 [crop] => )
)

So, I used array_keys() function to get the keys of the second array, and ran a foreach loop on the value returned by array_keys, and unset the elements of first array


$key_names= array_keys ( $array2 );
foreach( $key_names as $key ){
unset($array2[$key]);
}