Select Insert from multiple fields

No Gravatar

Today I needed to copy some records from one table to another.  Both tables didn’t have the same structure so I couldn’t select everything regardless of fields and dump the data into the second table. 

Instead I needed to SELECT the fields to INSERT INTO tableA

I then had to SELECT the field to copy from in the second table (tableB).

This is how the query looked

  1. $sql ="INSERT INTO `tableA` (`name`) ";
  2. $sql.="SELECT `tB`.`title` ";
  3. $sql.="FROM `tableB` AS `tB` ";
  4. $sql.="WHERE `tB`.`id` > ‘10′ ";
  5.  
Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Trying Google Chrome for the first time

No Gravatar

Its here Google Chrome has finally landed. Whoop

I’ve been testing some sites on it for the past 30 minutes and my overall impression is that it’s a very good clean and quick  browser. In fact I’m using it now to write this post.

My main point of interest lies in it’s rapid speed of opening up applications. Google Chrome allocates each tab to its own segment of memory which means that if one tab dies then the rest won’t follow. Simply close the broken tab and carry on.  

Obviously I couldn’t go through each feature in 30 minutes and it’s only in Beta version so I’m not going to jump on the Google band wagon just yet. However I am quite pleased with it’s performance. 

One thing it doesn’t have are any add-ons that FireFox has but I’m sure that in time these will be popping up in the open source community.  

Overall, I’m happy that another open source browser has surfaced as this helps developers like my self to create a better internet.

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Cant find package phpmyadmin E:

No Gravatar

I’ve got my hands on a nice server and when installing the phpmyadmin package I came across this error:

  1. sudo apt-get install phpmyadmin, I have an error "E: couldn’t find package phpmyadmin"

What’s happening is that the request is looking for the package in the E drive (the CD drive) and not in the universe repository. It can be a bit of a confusing error so I’ve decided to document how to solve it. I hope that it may prove useful for some.

Firstly the sources.list needs to be modified.

Simply do the following:
1. Modify the sources list:

  1. sudo nano /etc/apt/sources.list

Uncomment the last two lines:

  1. GNU nano 1.3.10                   File: /etc/apt/sources.list
  2. # deb cdrom:[Ubuntu-Server 6.06.2 _Dapper Drake_ - Release i386 (20080110.1)]/ dapper main restricted
  3. deb cdrom:[Ubuntu-Server 6.06.2 _Dapper Drake_ - Release i386 (20080110.1)]/ dapper main restricted
  4. deb http://us.archive.ubuntu.com/ubuntu/ dapper main restricted
  5. deb-src http://us.archive.ubuntu.com/ubuntu/ dapper main restricted
  6.  
  7. ## Major bug fix updates produced after the final release of the
  8.  
  9. ## distribution.
  10. deb http://us.archive.ubuntu.com/ubuntu/ dapper-updates main restricted
  11.  
  12. deb-src http://us.archive.ubuntu.com/ubuntu/ dapper-updates main restricted
  13. ## Uncomment the following two lines to add software from the ‘universe’
  14.  
  15. ## repository.
  16. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  17.  
  18. ## team, and may not be under a free licence. Please satisfy yourself as to
  19. ## your rights to use the software. Also, please note that software in
  20.  
  21. ## universe WILL NOT receive any review or updates from the Ubuntu security
  22. ## team.
  23.  
  24. # deb http://us.archive.ubuntu.com/ubuntu/ dapper universe
  25. # deb-src http://us.archive.ubuntu.com/ubuntu/ dapper universe
  26. ## Uncomment the following two lines to add software from the ‘backports’
  27. ## repository.
  28.  
  29. ## N.B. software from this repository may not have been tested a
  30. ## extensively as that contained in the main release, although it includes
  31. ## newer versions of some applications which may provide useful features.
  32. ## Also, please note that software in backports WILL NOT receive any review
  33. ## or updates from the Ubuntu security team.
  34. # deb http://us.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse
  35. # deb-src http://us.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse
  36. deb http://security.ubuntu.com/ubuntu dapper-security main restricted
  37. deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted
  38.  
  39.  
  40. #####UNCOMMENT THESES TWO####
  41. deb http://security.ubuntu.com/ubuntu dapper-security universe
  42. deb-src http://security.ubuntu.com/ubuntu dapper-security universe
  43.  

2.Then update the server

  1. sudo apt-get update

3. After any update have been installed you can finally install phpmyadmin

  1. sudo apt-get install phpmyadmin
  2.  

Hope this helps someone

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Change the SSH welcome message

No Gravatar

Each Ubuntu server displays the following message when a user logins in via SSH:

  1. Linux <SERVERNAME> <KERNEL> #2 <TIMESTAMP>
  2.  
  3. The programs included with the Ubuntu system are free software;
  4. the exact distribution terms for each program are described in the
  5. individual files in /usr/share/doc/*/copyright.
  6.  
  7. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
  8.  
  9. Last login: <TIMESTAMP> from <IP ADDRESS>

To change the above all thats need is to modify the /etc/motd file

I use nano for this

  1. sudo nano /etc/motd

Once saved log back into the server and the message will be changed.

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

htaccess deny access to folders

No Gravatar

A website is made up from several folders which contain files such as style sheets and server sided code. By default these files and folders can be accessed via a browser leaving whatever contents in those folder open to prying eyes.

Folder structureLets say we have the following folder structure. (This is not the typical structure that I would use myself but is a good enough example). If a browser was pointed at www.site.com/css/ the user would see the code in a text format.

You may think that leaving you style sheet directory open isn’t much of a big risk to your site but what about your /cmd/inc folder.  This could hold php files that contain database access details or the /img directory may be a family photo album. Is it a risk now?

Closing the door to all

To deny direct access to your folders  all that is needed is a .htaccess file and three words…. “Deny from all”

Simply create a .htaccess file in the folder you want to lock down and add the following to it:

  1. # Deny access from all
  2. deny from all
  3.  

Now if you try and access that folder via a browser you will get a forbidden warning and a 404 error will executed.

Leaving it open to a selected few

You may wish to allow relatives access to your photo albums in your/img directory but still keep it closed to everyone else. In order to achieve this you will need to know the IP address of the machines that you want to allow access too. Once you have these details modify your .htaccess file to look like this:

  1. # Deny access from all except uncle Ronny
  2.  order deny,allow
  3.  deny from all
  4. # Exception for uncle Ronny
  5.  allow from
  6. # Where  is an ip in the format of 00.00.0.0
  7.  

Tarting up the 404 page

When a user tries to access a forbidden directory they will redirected to a 404 page. This looks a bit ugly and not very professional. In my previous post (htaccess error pages) I have discussed how to use htaccess to redirect certain error pages to nicely formatted pages which can consist of server and client sided code.

Conclusion

I hope you will agree it doesn’t take to much effort to secure your folders. If you have loads of directory’s that you want to keep private you could link them symbolically to a htaccess file outside of the root folder.  But remember that all the linked htaccess files will have the same settings so I would only do this if you don’t want to allow any exceptions.

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Use htaccess to increase max_file_size

No Gravatar

In the PHP Ini configuration file there is a setting called upload_max_filesize which controls the maximum size that a file can be when uploaded via a form. Any files that are larger then the set value will not be uploaded and result in error code 1 (The file is to large).

If your application allows users to uploaded images or pdfs to a site then the chances are you will need to adjust this value to allow bigger files to be uploaded.

Unless you have access to the php ini file you will need to use htaccess to set the new limit.

Add the following to your htaccess file

  1. # Increase the upload_size to 8mb
  2.  php_value post_max_size 8M
  3.  php_value upload_max_filesize 8M
  4.  

This will now allow you to upload files that are up to 8 megabytes in size.

Further resources

PHP.net

CakePHP can’t find Group By support

No Gravatar

I haven’t been able to find any support for the `GROUP BY` SQL clause in model file.

  1. class Post extends AppModel {
  2.         var $name = ‘Post’;
  3.         var $order =‘Post.updated_date ASC ‘;
  4.        # The below doesn’t work
  5.         var $group = ‘Post.status’;
  6. }

The model uses a HABTM relationship and I’ve tried adding the clause in the controller:
$list = $this->Post->find(’all’,null,array(’group’=>’Post.Status’));

I have opened a post on Google Groups to see if anyone can help me out.

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

CakePHP Caching problems

No Gravatar

I ran into a strange cakePHP error the other day. CakePhPI was adding new tables to a database as well as creating their models and controllers but I couldn’t make the scaffolding to work. The debug message insisted that the tables could not be found.

After double checking for typos in file names I turned to goggle for help and quickly found a logical solution. The models are cached and the new model for the new table wasn’t included in the cached files and thus the error was shown.

CakePHP caches an awful lot of data to make your application run faster and reduce load on the server. The cached files are found in the tmp directory in the app folder. If you have a look in there you will find a model directory.

My new model wasn’t amongst these cached files and that was causing the error. While Googling further I found that cakePHP will rebuild the files in the cached directories if they are not present.
So by deleting all the cached models and refreshing the site cake rebuilt the cached files including my missing model. This fixed the error and I could get on with my work.

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

10 Basic Linux Security Tips to Implement

No Gravatar

The following article describes 10 of the most basic security practices that any Linux administrator should undertake. They should be quite routine and self explanatory but it’s always good to be reminded.
I especially like point 10:

A message seen twice is better than no message at all

If aren’t sure that your secure then the chances are your not!

Personally my security procedures include the applications firestarter and clam. I have also written a bash backup script that creates archives of specified folders each week.
However I should check my log files more regularly. Maybe I should look into building a script that can do this automatically.

All the other points are quite valid and should be taken seriously.
Hats off to the author

read more | digg story

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

IE Broken Identifier hack

No Gravatar

I have updated my post CSS IE FF Hacks and have added the broken Identifier hack to the list.(point 3.1)
This hack allows you to change a style declaration for all versions of Internet Explorer including version 7. When added below a valid style deceleration the outcome will be correctly rendered in all other browsers and different in the versions of IE.

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb
Next Page »

Advertisement

Advertisement