GreyPilgrim Posted February 22, 2007 Share Posted February 22, 2007 Newbie etc. Can you tell me what the problem is with this? I've installed mySQL 5 on my home pc and the command line interface seems to be working fine - I'm well away with creating tables and populating them etc I'm trying to run some php code to connect to mySQL and I'm getting a blank screen: =========================================== <?php // Set the database access information as constants. DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); echo'Checkpoint1'; $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() ); echo'Checkpoint2'; @mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() ); ?> =========================================== I copied this from a textbook I'm reading but I put in the "checkpoint1" and "checkpoint2" echoes as simple debug pointers. All I'm getting is "checkpoint1" - nothing else at all! I wasn't prompted for a username when installed mysql so I'm assuming its 'root'. I specified the password as 'password', and created the database as 'sitename' Hope you can help>? Quote Link to comment Share on other sites More sharing options...
AdRock Posted February 22, 2007 Share Posted February 22, 2007 I have this code in a seperate file and I call it by using include_once "connection.php" There is a good site for installing php, apache and MySQL....http://www.puremango.co.uk/cm_wamp_97.php <?php $host="localhost"; $user="username"; $password="password"; $database="database_name"; mysql_connect($host,$user,$password); @mysql_select_db($database) or die( "Unable to select database") ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2007 Share Posted February 22, 2007 $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() ); Try not surpressing the error so the or die can actually be reached. $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() ); Quote Link to comment Share on other sites More sharing options...
GreyPilgrim Posted February 22, 2007 Author Share Posted February 22, 2007 Try not surpressing the error so the or die can actually be reached Hi there, can you elaborate on this but bear in mind you're talking to a newbie I didn't purposefully supress or unspurpress errors....is this done in the php ini file? Quote Link to comment Share on other sites More sharing options...
corbin Posted February 23, 2007 Share Posted February 23, 2007 No. It's done by the @ operator. At the beginning of a function (and maybe some other things too... darn memory...) it means 'If this returns any errors, pretend they don't happen.' I made the same mistake for almost three months. The way I learned to select databases was by @mysql_select_db();. I saw that and just always assumed the @ had to be there until one day someone told me . Anyway, if you remove the @, it won't suppress errors and you should be able to figure out what's wrong. My best guess is that you don't have mysql installed in PHP. Try making a blank file and seeing what this returns: <?php if(function_exists('mysql_connect')) { echo "It exists!"; } else { echo "You need to install MySQL!"; } ?> Quote Link to comment Share on other sites More sharing options...
GreyPilgrim Posted February 23, 2007 Author Share Posted February 23, 2007 I'm not scared of appearing stupid but I don't have a clue here can someone help please? In a sort of private message sense? GP Quote Link to comment Share on other sites More sharing options...
AdRock Posted February 23, 2007 Share Posted February 23, 2007 Have you installed phpMyAdmin....that is really useful Quote Link to comment Share on other sites More sharing options...
GreyPilgrim Posted February 27, 2007 Author Share Posted February 27, 2007 No. It's done by the @ operator. At the beginning of a function (and maybe some other things too... darn memory...) it means 'If this returns any errors, pretend they don't happen.' ARGH. So easy when you have some help. I didn't realise the @ did that. Anywoo, removing it led me to realise I had screwed up some stuff in the php.ini file Thanks guys - lifesavers. GP Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.