PDA

View Full Version : connecting to database


giants10
04-24-2008, 12:16 PM
can anyone please tell me if the following is a good code to connect to the database

<?php

function db_connect()
{
$result = mysql_pconnect('localhost', 'bm_user', 'password');
if (!$result)
return false;
if (!mysql_select_db('localhost'))
return false;

return $result;
}

is there anything i should add to the code?

Fumigator
04-24-2008, 06:48 PM
http://codingforums.com/showthread.php?t=68462

You should display mysql_error() (and probably abort the script using die() ) if the connect function fails. And why are you opening a persistent connection? If you're on a shared host you'll run out of connections if your website is used by more than 3 or 4 people at a time. Oh and your PHP coding is kinda funky, though it will work.