What does this PHP file means? Is it about Database? I'm confused...

14 replies
Hi there,

I was trying to figure out what should I do with these information listed below.
Should I create a table of database? If so, how should I do that? I am totally lost and need some help from you guys.


<?php
@require (dirname(__FILE__) . '/split-settings.php');
$con = mysql_connect($settings['db_host'], $settings['db_username'], $settings['db_password']);
mysql_select_db($settings['db_name']);
?>
#confused #database #file #means #php
  • Profile picture of the author bazzais
    What script are you trying to use, is there not a helpfile or an sql command to use to install it?

    That code is indeed a connection script so you will need credentials and a database to log into.

    Ta

    Baz

    Originally Posted by AidenChong View Post

    Hi there,

    I was trying to figure out what should I do with these information listed below.
    Should I create a table of database? If so, how should I do that? I am totally lost and need some help from you guys.

    {{ DiscussionBoard.errors[1433163].message }}
  • Profile picture of the author AidenChong
    Hi Baz,

    It's a tracking tool which I wanted to install in my own server. Unfortunately, After uploading the appropriate files into my server, I found out that I don't have the helpfile anymore, and there is no sql command to use to install it.

    By only looking at the limited resource, Baz, are you able to get to know about what steps do I need to do first, in order to create a database for the tracking tool?

    Thanks a lot for your prompt reply.
    {{ DiscussionBoard.errors[1433195].message }}
  • Profile picture of the author dilqncho
    In this split-settings.php file to write the name database, username, password. Of course, who wrote in phpmyadmin and must go If you can not say what the script and show a demo
    {{ DiscussionBoard.errors[1433330].message }}
  • Profile picture of the author Elliott Bean
    Creating a database is easy. Login to your admin panel for your site.
    Go to the databases and click on MySQL databases.


    Where it says "create database" type in myDB and press create.



    Where it says "add new user" type in a username and a password (you may have the type the password in twice). Then click create user.


    Where it says "add user to database" select the database you have just created and the user you have just created and click add.


    On the following page click on "all privileges" and then "click make changes".


    This allows that particular user to connect to the myDB database and carryout all kinds of changes to any tables in that database. You can limit what the user is capable of by only selecting the commands which he can carry out rather than all privileges.


    You can either change the values of $settings['db_host'], $settings['db_username'], $settings['db_password']);
    mysql_select_db($settings['db_name'] within split-settings.php or amend the code you pasted above as follows:

    $con = mysql_connect("localhost", "username", "password");
    mysql_select_db("dbname");


    If you do it this way make sure the username and dbname have the prefix that is shown when you created them. This is normally your cpanel username with an _

    You'll probably have to look through the split-settings.php to see the name of the table that is used and create that table within phpmyadmin (if there isn't a create table command anywhere in any script)


    Signature

    {{ DiscussionBoard.errors[1433359].message }}
  • Profile picture of the author AidenChong
    Wow Elliott Bean,

    After reading your explanation, a simple thank you was totally not enough to express my gratitude.

    However, I am really a stupid noob when it comes to technical stuff like this.

    Do you mind if I PM you about my problem?

    Thanks a lot for your explanation. Feel embarrass that I don't really know what to do about the precious information which you've given up there

    dilqncho, thanks for your help too.
    {{ DiscussionBoard.errors[1433819].message }}
  • Profile picture of the author Elliott Bean
    send me a PM I don't mind
    Signature

    {{ DiscussionBoard.errors[1435071].message }}
  • Profile picture of the author dilqncho
    Write here the theme that we all can help you
    {{ DiscussionBoard.errors[1435136].message }}
  • Profile picture of the author AidenChong
    dilqncho, thanks for your help, but I really don't know what to write out, and where to head for.

    Nevermind cause I have got Elliott helped me out now
    {{ DiscussionBoard.errors[1435145].message }}
  • {{ DiscussionBoard.errors[1435255].message }}
  • Profile picture of the author phptechie
    Hi,

    This is just a single file with the database connection & if you create the database & the split-settings.php file with the database parameters will not help you. Because it might be a full script which might require tables for the script to work fully.

    So if you purchased the script , then request the script vendor to install this script for you rather than trying to fix it & break your head :-)
    {{ DiscussionBoard.errors[1458424].message }}
  • Profile picture of the author AidenChong
    Hi Warrich and Sundar,

    Thanks for your words and thanks for your help.

    Anyway, I have got that problem solved out and it's running smoothly now

    Thanks a lot...
    {{ DiscussionBoard.errors[1458451].message }}
  • Profile picture of the author Mr. Enthusiastic
    Yes, this is standard code to connect to a database. And it's a great opportunity to walk through some code step by step to build understanding of how a script is organized.

    The code does not create the database, it assumes that you already have a database created before this code is run.

    To connect to a database you need to know which server hosts the database program.
    But it's not enough to know which machine, you need to have a user account for the database program: username and password.
    The database program might contain several databases, for example one for orders and another for shipments. So you need to specify which database to use by indicating its name.

    In PHP, $settings is a place to keep track of information that is re-used throughout the program so you only have to change it once. $settings can keep track of any number of settings, and you give it the name of the particular setting you are interested in. This code assumes that $settings has already been set up with the "fill in the blanks" information for the database host machine, username, password, and database name.

    The prefix db_ will make it easier for other programmers to realize that this is database information. If there were also shipping settings, they might use, say $settings['ship_UPSPickuptime'] while code to deal with payroll might include $settings['payroll_SocSecTax'], to make up some examples on the spot.

    The mysql_connect command tells the PHP runtime to establish a connection with a mysql database. This is like making a phone call to someone who can look something up for you. To do this, you already need to have mysql running and the connect command needs to know the host, username, password, and database name. This code gets that information from $settings.

    mysql_select_db then gets some information from the database. This is like asking a question of the librarian once you have them on the phone. But it won't work if the connection to the database wasn't established first.

    My guess is that the code fragment above was part of a larger package. There was probably some other script that should be run first to create the database and store its settings in $settings. If you can find that first script - it might be called "install," "configure," "administrator," "setup" etc. - then it should get things set up for you. Otherwise, you'll have to create a mysql database using other mysql tools, then rerun this script once you have the database ready.

    Chris
    {{ DiscussionBoard.errors[1459773].message }}
  • Profile picture of the author Jawshh
    Log into your cpanel provided by your host. Scroll down a bit and you will see "MySQL Database Wizard" click on it and you will be ask for database name, username and password. Just put anything. Then make sure you select "All Privileges" when asked.

    Now you need to edit the php file you provided in your first post. It will be:

    <?php
    @require (dirname(__FILE__) . '/split-settings.php');
    $con = mysql_connect($settings['localhost'], $settings['The Username you've put when creating database'], $settings['The password you chose while creating the database']);
    mysql_select_db($settings['The database name you've put when creating database']);
    ?>

    Hope this helps.
    Signature

    Get a Website Loaded With Unique Content Every Month For Free. Check it out NOW!!!

    Advanced Internet Marketing Tactics

    {{ DiscussionBoard.errors[1460039].message }}
  • Profile picture of the author AidenChong
    Thanks for all of the help provided in this thread. I have got it solved earlier on. Thanks a lot, people
    {{ DiscussionBoard.errors[1461979].message }}

Trending Topics