SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help connecting to MySql from PHP

    Hello all,

    Please be patient with me as I try to explain my problem, I'm a total newb to all of this. I could really use some assistance on this as I have searched for days trying to find the answer and have failed to find the answer.

    The setup you need to know:

    1) Apache Server is installed and up and running fine
    2) MySql service is running
    3) I can use mysql through command console to see my DB and tables
    4) I'm running on Windows XP Media Edition

    What's happenning:

    As I work my way through the tutorials in the SitePoint Book titled "Build your own Database Driven Web Site, Using PHP and MySQL" everything worked fine; installation of Apache, installation of MySQL, and even the chapters on adding tables..etc. The problem occurs when I get to the part where I have to connect to MySql through PHP.

    When I type http://localhost:8080/test/chapter4/connect and hit enter in the browser I get nothing...ziltch...nada...If I view source it's empty. I've tried variations of connections and still I'm getting nothing. HALP! what am I doing wrong? For those of you familiar with the book I'm stuck on page 121.

    I suspect the problem is something related to the root of mySql but I haven't been able to figure out what. Is there something I have to do with mySql to tell it the root?

    Two files (located at htdocs/test/chapter4/connect)

    the scripts:

    index.php


    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost:8080''root''testpassword');
    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';
    ?>

    output.html.php


    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <title>PHP Output</title>
            <meta http-equiv="content-type"
                    content="text/html; charset=utf-8"/>
        </head>
        <body>
            <p>
                <?php echo $output?>
            </p>
        </body>
    </html>
    Last edited by SpacePhoenix; Dec 11, 2010 at 17:19. Reason: put php tags round php code to improve readability


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
  •