Pacecode Blog Tips, Scripts and More…

25Dec/083

Important MySQL Questions and Answers

How many types of join are supported by mysql? Which are they? Explain:

ans: there are three types of joins supported in mysql as inner, right and left.
The inner join displays all the rows from both tables where match is found.
Left join returns all the rows from first table even if the match is not found in second table.
While the right join returns all the rows from second table even if match is not found in first table.

What are the advantages of mysql comparing with oracle?

MySql has many advantages in comparison to Oracle.

1 - MySql is Open source, which can be available any time

2 - MySql has no cost of development purpose.

3 - MySql has most of features , which oracle provides

4 - MySql day by day updating with new facilities.

5 - Good for small application.

6 - easy to learn and to become master.

7 - MySql has a good power these days.

even though MySql having so many advantages, Oracle is best database ever in Software development.

What are the limitations of mysql in Comparison of Oracle?

  • Mysql supports six different types of tables, four of which do not support transactions (MyISAM, MERGE, ISAM, and HEAP)
  • MySQL only supports one index type
  • Unlike Oracle, MySQL date data types can store invalid dates, do not support time zones, and the precision of time values is limited to one second.

How many drivers in MYSQL?

There are eleven drivers in MYSQL .Six of them from MySQL AB and five by MYSQL Communities. They are1.PHP Driver2.ODBC Driver3.JDBC Driver4.ado.net5.mxj6.CAPI1PHP DRIVER2.PERL DRIVER3.PYTHON DRIVER4.RUBY DRIVER5.C++ WRAPPER

How are triggers created in MySQL?

CREATE TRIGGER `tgr_name` AFTER UPDATE ON `addresses` FOR EACH ROW begin

update products set countryName = new.countryName where products.shippingAddressId = old.id;

end;

3Dec/081

Problem with transparent image resizing? – PHP

You will get black background if you resize a transparent image. To fix it, You need set alpha channel imagecolorallocatealpha to 127. With imagecolorallocatealpha, it will allocate a color for an image.

Usage:
int imagecolorallocatealpha ( resource image, int red, int green, int blue, int alpha)

From PHP manual:
imagecolorallocatealpha() behaves identically to imagecolorallocate() with the addition of the transparency parameter alpha which may have a value between 0 and 127. 0 indicates completely opaque while 127
indicates completely transparent. Returns FALSE if the allocation failed.

Before using it, you must set to false the blending mode for an image and set true the flag to save full alpha channel information.

Example:

<?

$newImg = imagecreatetruecolor($nWidth, $nHeight);

imagealphablending($newImg, false);

imagesavealpha($newImg,true);

$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);

imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);

imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);

?>

Another way to fix this issue:

phpThumb() - Resize images on the fly

Description: phpThumb() uses the GD library  to create thumbnails from images (JPEG, PNG, GIF, BMP, etc) on the fly. The output size is configurable (can be larger or smaller than the source), and the source may be the entire image or only a portion of the original image.

Download: Download

Site: phpThumb()

Demo: Demo

Installation:

1. unzip the folder and upload the content into the server
2. give the correct path of the phpThumb.php and image path as per the following syntax

Resize Syntax:
<img src="../phpThumb.php?src=images/watermark.png&bg=FFFFFF&f=png" alt="">
<img src="../phpThumb.php?src=images/watermark.png&bg=FFFFFF&f=gif" alt="">
<img src="../phpThumb.php?src=images/watermark.png&bg=FFFFFF&f=jpeg" alt="">

where the bg=FFFFFF represents the bg color of your transparent image.