Jump to content
Larry Ullman's Book Forums

Mysql_Connect Statement Not Connecting To Database

Recommended Posts

I am attempting to try and connect to my mysql database.  I am using apache webserver.  When I run a php script through localhost through my browser the script works well.  When I run my mysql_connect.php then all I get is a blank page.  nothing happens. I placed an echo statement at the end to verify that it connected.  The echo statement doesn't appear when I refresh the page.


Here is my code:


<?php # Script 7.2 - mysql_connect.php
// This file contains the database access information. 
// This file also establishes a connection to MySQL and selects the database.
// Set the database access information as constants.
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'xxxxxxxxx');
DEFINE ('DB_HOST', 'localhost:3306');
DEFINE ('DB_NAME', 'reg');
// Make the connnection.
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
// Select the database.
@mysqli_select_db(DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
echo 'hello';
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...