Re: Connection to db

From: Date: Sun, 25 Aug 2002 00:21:57 +0000
Subject: Re: Connection to db
Groups: php.general 
Request: Send a blank email to php-general+get-114006@lists.php.net to get a copy of this message
>I've use this script with many db connections at other domians I manage >and it works fine: > >> // Connect to the database server >> $dbcnx = @mysql_connect("localhost", >> "username", "pass"); >> if (!$dbcnx) { >> echo( "<P>Unable to connect to the " . >> "database server at this time.</P>" ); >> exit(); >> } >> >> // Select the newspost database >> if (! @mysql_select_db("name_of_db") ) { This should probably also be 'newspost' instead of 'name_of_db' >> echo( "<P>Unable to locate the newspost " . >> "database at this time.</P>" ); >> exit(); >> } > > >For some reason, when I try it with a newer domain, I get "document >contains no data" > >I've tryed this suggested by "Sami Mahamed" on this list.. THANKS!, >The document works but when I try to *insert* into the db it returns >error "no db selected" Your mysql_select_db *should* be displaying an error message about 'newspost' then, right? >> $dbhost = ''; // MySQL server hostname >> $dbuser = ''; // MySQL username >> $dbpass = ''; // MySQL password >> $dbname = ''; // MySQL database name >> >> mysql_connect("$dbhost", "$dbuser") && >> mysql_select_db("$dbname") >> or $failed = "Could not connect to database."; -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#114006) next »