Connect MySql with PHP

Discussion in 'Databases' started by Shanna Holloway, Dec 21, 2011.

  1. #1
    I have a Mysql database and I have written the PHP script to be able to link into it from the PHP but I think I missed something. I cannot connect and the only documentation I can find is to save my php files to my web server. I am a little confused about what that means. I have Apache running is there somewhere in there that I am supposed to save my php files to?

    Thanks!
     
    Shanna Holloway, Dec 21, 2011 IP
  2. kind_of_the_cash

    kind_of_the_cash Active Member

    Messages:
    852
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    85
    #2
    You can do it in using above code
     
    kind_of_the_cash, Dec 21, 2011 IP
  3. Shanna Holloway

    Shanna Holloway Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok I have that.. here is my php code now. my problem is that it is not connecting and i think it is where the files are saved. What I have been reading is that I have to save the file to the web server. Is that my apache server and if so how do I accomplish that?

    <?php
    $link = mysqli_connect('localhost', 'root', 'PiS1009Je');
    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, 'hoist'))
    {
    $output = 'Unable to locate the hoist database.';
    include 'output.html.php';
    exit();
    }

    $output = 'Database connection established.';
    include 'output.html.php';
    ?>
     
    Shanna Holloway, Dec 21, 2011 IP
  4. kind_of_the_cash

    kind_of_the_cash Active Member

    Messages:
    852
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    85
    #4
    Do you want to run it on your own computer ? without uploading to the server ? Then you have to download WAMP (Windows, Apache, Mysql, PHP) or LAMP (Linux, Apache, Mysql, PHP) server to install.

    Tip : if your using windows you can download "easyphp" (just google it) and run that WAMP on your computer.
     
    kind_of_the_cash, Dec 21, 2011 IP