First check have u uncommented mysql extension in php.ini file. Then run phpinfo to check whether it is working or not. And try ur code again.