基本的に、コンテンツを ico タイプとして出力するようにスクリプトに指示する必要があります。
<?php
//Getting your image
$data=file_get_contents("http://www.google.com/favicon.ico");
$data = base64_encode($data);
//If your storing in the db then you do the query ect togo get the data string
//Then echo out like this
header('Content-Type: image/vnd.microsoft.icon');
echo base64_decode($data);
?>
ヘッダーを設定する前に何も出力できないことを覚えておいてください。おそらく、ファイルを取得して出力するための別のスクリプトが必要になるでしょう。
<img src="get_ico.php?id=1"/>
次にget_ico.php
<?php
//Connect db ect
//Query db for $_GET['id']
//Then echo out like this
header('Content-Type: image/vnd.microsoft.icon');
echo base64_decode($row['image_data']);
?>