Setting Up Mysql Databases!

Setting up MySql Databases!

Setting up MySql Databases.

First of all, you will need a MySql database with PHP. If you don’t have one you can get one from here.

After you get there you will see the home page, Find the Sign Up! button to the bottom right.

Fill out the form accordingly and hit submit

You will be brought to a Account Overview page. Click on Enter Control Panel. You will be brought to a page that looks like this.

K now, to begin lets start off by setting the files up. I can’t upload them so I have to paste them. Name them exactly as I do. (Copy and paste into Notepad or whatever you use and save the name as I have)

1) cfg.php

PHP Code: $Mysql_Host = ”HOST”;
$Mysql_User = ”USER”;
$Mysql_Pass = ”PASS”;
$Mysql_DB   = ”DB”;

$con = mysql_connect($Mysql_Host, $Mysql_User, $Mysql_Pass);
if (!$con)
{
    die(mysql_error());
} else {
    if (!mysql_select_db($Mysql_DB))
    {
        die(mysql_error());
    }
}
?>

2) add.php

PHP Code: include ”cfg.php”;

if (isset($_POST['proggy']))
{
    $Prog = $_POST['proggy'];
    
    if (empty($Prog))
    {
        echo ”Error”;
    } else {
        $sql = mysql_query(”INSERT INTO `proggies` (Proggy) VALUES (’$Prog’)”);
        if (!$sql)
        {
            die(mysql_error());
        }
        exit;
    }
}
?>

“>
    

3) show.php

PHP Code: include ”cfg.php”;
    
    $p = $_GET['page'];
    if (empty($p) || $p == ”)
    {
        $p = 1;
    } else {
        $p = $_GET['page'];
    }
    $limit = $_GET['max'];
    if (empty($limit) || $limit == ”)
    {
        $limit = 5;
    } else {
        $limit = $_GET['max'];
    }
    $start_from = ($p-1) * $limit; 
    $result = mysql_query(”SELECT * FROM `proggies` LIMIT ”. $start_from .”,”. $limit);
    $total = mysql_query(”SELECT count(*) FROM `proggies`”);
    $total = mysql_result($total, 0);
    if ($p > ceil($total/$limit))
    {
        echo ”Incorrect pageID“;
        echo ”Back to page 1″;
        exit;
    }

    echo ”Page(s): || ”;
    $i = 1;
    while ($i <= (ceil($total/$limit)))
    {
        if ($p == $i)
        {
            echo ”“. $i .” || ”;
        } else {
            echo ”". $i .” || ”;
        }
        $i++;
    }
    echo ”";
    while($row = mysql_fetch_array($result))
    {
        echo ”“. $row['scn'] .”“;
        echo ”

". stripslashes($row['Proggy']) ."

“;
    }
?>

Now after you have done that, go back to the Control Panel (C-Panel) on the site and find the File Manager button near the middle of the page and click it. You may have to sign in again. (Your pass is what you used to signup with)

You will be brought to a page that looks like this. Click on public_html.

Now click on upload and you will be brought to a upload page. Upload all three files. Click on the green check mark.

Make sure you see this conformation and hit the blue arrow to go back.

Now, delete the default.php file. It is necessary, especially if you want to make your site look a little better. Later we will setup the cfg.php but have to setup the database now. Click on the MySQL button to setup the database.

Fill in the Create new database form and click Create Database. (You can use any name you want.)

You will see a screen that has information that you’re going to need. So write that down and go back to the File Manager and go back to cfg.php and click edit to the right.

Edit cfg.php with what you got from the step above so it looks like this. Hit the blue save button then the blue arrow after it saves. You can exit this after.

Now go back to the C-Panel and click on the phpMyAdmin button.

Under the List of Databases click on EnterphpMyAdmin and you will be brought to this page.

Click on Import in the upper right of the screen.

A upload form will be the next thing you see. But first, download the DB.txt that I have attached to this tut. Now click on browse and locate and click on the DB file. Click on Go at the bottom. To the left you will see “proggies” under your database name. Click it. Now for a little editing. Click on the green pencil.

Click on the Collation drop down menu. Scroll down to the very bottom. Select the utf8_unicode_ci. Then hit save.

Now you don’t have to but I like setting everything up for unicode. If you want you can click on your database name to the left. Click on Operations near the top right. Find the Collation section near the bottom and on the drop down menu use the unicode specified above located at the very bottom. Click on Go to save it. Now, click on “proggies” on the left and click on Operations also. Do the same for the collation. If you don’t do that then click on “proggies” and add another field to the database. Click on Go since everything is setup already.

Now just set it up like the following. Hit Save.

You’re probably wondering what that does. It allows you to search for proggies by name on your site. So you can filter like this sitename.com/add.php?name=whatever

So you’re all set up and ready to use this database for the function or whatever else you need. But right now all your public_html files are viewable and looks nasty. Lets make your site at least look better. Find and click the Website Builder button which is in the same line as the phpMyAdmin and MySQL.

Click on the first step and just follow the instructions for setting up the design you want.

And there you have it. Your own MySQL Database with PHP! This can be very useful with the function.

Thanks for reading!

Leave Your Response