1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Rep Power

    SQL connection string

    Hi Guys Im creating my own website and I have never connected via SQL before only bu using MS Access.

    I'm using Heart Internet and Joomla (I'm hard coding this as I'm looking for my first graduate job)I take it with the variables I have to define where my site is, what the name of the website is and the user name and password of the backend of the SQL database?

    <?php # Script 7.2 - mysql_connect.php

    // This file contains the database access information.
    // This file also establishes a connection to MySQL and selects the database.

    // Set the database access information as constants.
    DEFINE ('DB_USER', 'username');
    DEFINE ('DB_PASSWORD', 'password');
    DEFINE ('DB_HOST', 'localhost');
    DEFINE ('DB_NAME', 'sitename');

    // Make the connnection.
    $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

    // Select the database.
    @mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    this is a PHP question, not a MySQL question. I'll ask a moderator to move your thread.

    Copypasting code from random websites is generally a terrible idea. Most loose PHP code you'll find online is hopelessly outdated, badly written and insecure. That's really not what you want to have on your server, accessible by the whole world.

    The code you got there is no exception. It's at least 10 years old, it has no security whatsoever, and it's just crap.

    If you want good PHP code, you have to actually learn to program from proper sources. The most obvious and reliable source is the PHP manual. If you search for "mysql_connect", the first thing you'll see is a big red warning box telling you that this function is deprecated and what you should use instead. Follow the links and learn more. While you do that, you'll get plenty of keywords to type into Google and find further information -- like this PHP tutorial for MySQL user.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo