Question: I recently switched from MySQL to PostgreSQL. I have one problem left however.

Previously, I would store small images in the BLOB format in MySQL.

PostgreSQL doesn't know such thing as a BLOB.

I tried using BYTEA field type instead. This actually inserts an large (hexadecimal?) string I guess, but now I'm stuck trying to get this string back to displaying an actual image in PHP..

Any ideas? Thanks in advance.

Here is a piece of code I use to save the image in the database:

```
$data = bin2hex(file_get_contents('php://input'));

if (!empty($data)) {
  $sql = "UPDATE asset SET data = X'%s' WHERE uuid = '%s'";
  $args = array($data, $asset_uuid);
}

```

psql (9.1.3) and php 5.3.6 are used

Answer: 
No, it's not "bad practice". It just depends on the situation. 

For example, as an Android, if the user inputs a string "123a" into a text box that is only supposed to accept integers, and is subsequently parsed, an exception will be thrown causing the application to crash. In this case, it would make perfect sense to catch the exception and prompt the user to re-enter the text.
Its `Not about how good you code looks`, but `how good your code works`..........
`Ya offcourse it should be readable,` **As famously said...**

**Any fool can write a code that computer can understand, but only great programmers write codes that humans can understand.**

Its perfectly fine in some cases where, you need to have such kind of exceptions in place.

`When you want to catch multiple exceptions which belong to the same inheritance tree,` `then create a try block, and multiple catch blocks from more specific to more` `abstract.`

eg:

```
`Animal <--- Carnivores <--- Dog`

```

Now suppose there is a **DogException, CarnivoresException, AnimalException**.

Then it must be like this,

```
try{

           // your code 

     }
      catch(DogException d){}
      catch(CarnivoresException c){}
      catch( AnimalException a){}

```

**Above catches has been cascaded from more specific to more abstract so that the exception is caught to it very cause.**

**If there is no inheritance, then catch can be in any order...**