Developers Archive for December, 2006

Storing images in mysql database

Storing images in mysql database Friday, December 29th, 2006

Mysql database can be used to store images, in other words as an image library. You ‘ll store the data using a “blob” type here.
At first read the image as byte format then store. if image length is less than 149000, then it can be done.

sample coding

$instr = fopen(”image.jpg”,”rb”);
$image = addslashes(fread($instr,filesize(”image.jpg”)));
if (strlen($instr) < 149000) {
mysql_query (”insert into pix (title, imgdata) values (”Image”, \”".$image.”\”)”);
} else {
$errmsg = “Too large!”;
}

Regular expression in MYSQL

Regular expression in MYSQL Friday, December 29th, 2006

Regular expression is one of the most powerful tool for the developer
who are dealing with the string in any language .Mysql also support
regular expression patten match by which we can make our work more
efficient

the operator of Regular expression in REGEXP

examples
regexp ‘^abc$’ => will match exactly abc
regexp ‘^ab{2}c$’ => will match exactly abbc
regexp ‘^ab{0,2}c$’ => will match ‘ac’ or ‘abc’ or ‘abbc’
regexp ‘^ab{2,}c$’ => will match ‘abbc’,'abbbc’,…….

We can use the regexp instead of ‘OR’.

We can replace the query

” select *
from user
where name like ‘%alpha%’
or name like ‘%beta%’

With

select *
from user
here name regexp ‘(alpha|beta)’

both will do the same function.

register_shutdown_function

register_shutdown_function Friday, December 29th, 2006

register_shutdown_function
- used to register functions which will be called after script reaches end.
- we can register multiple functions using register_shutdown_function

Arguments:
- func (which takes function name)

Example:
function myFunction(){
echo “My Fucntion”;
}
register_shutdown_function(myFunction);

echo “My Script”;

Usage:
Basically, it is used for clean up purpose.
For example, to close the file handles, close database connections,close sessions and etc.

Note : don’t give exit() in any registered function. if you give exit in a function, other register functions won’t be called.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.