SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Connecting to MySQL local host

    Hi I am brand new to PHP/MySQL development, and I'm following through the Build Your Own Database Driven Web Site 4th Ed. text. I've installed PHP, MySQL, and Apache separately and have used the following code to connect to MySQL:

    Code PHP:
    <?php
    $link = mysqli_connect('localhost', 'root', 'PASSWORD');
    if (!$link)
    {
    	$output = 'Unable to connect to the database server.';
    	include 'output.html.php';
    	exit();
    }
     
    if (!mysqli_set_charset($link, 'utf8'))
    {
    	$output = 'Unable to set database connection encoding.';
    	include 'output.html.php';
    	exit();
    }
     
    if (!mysqli_select_db($link, 'ijdb'))
    {
    	$output = 'Unable to locate the joke database.';
    	include 'output.html.php';
    	exit();
    }
     
    $output = 'Database connection established.';
    include 'output.html.php';
    ?>

    This is verbatim from the book (except I use the correct password for the root user). When I load it up in a browser I do not get any of the error messages, but I do get a totally blank page. What does this mean? When I declare $link to be zero, I do get the first error message. Any thoughts would be very helpful.

    Thanks, Grace

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Does output.html.php have any output? That's what would be displayed. If it's empty then a blank page is correct.

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes output.html.php has the following

    Code HTML4Strict:
    <body>
    		<p>
    			<?php echo $output; ?>
    		</p>
    	</body>


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •