Results 1 to 7 of 7

Thread: How to connect database!

  1. #1
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to connect database!

    I'm learning about php language. Making statements such as how to connect to mysql database.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,734
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Did you have a question?
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    381
    Thanks
    6
    Thanked 35 Times in 33 Posts

    Default

    I think he is asking how do you connect to a database in php:
    Here is a good way to start:
    http://www.w3schools.com/php/php_mysql_connect.asp
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  4. #4
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    you really need to ignore the above post to use MYSQL or MYSQLI they are depricated in php5.3 adn GONE in php5.4

    if you use mysql(i) you will Never be able to upgrade beyond php 5.3 unless you rewrite your script.

  5. #5
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The first thing to do is connect to the database.The function to connect to MySQL is called mysql_connect. This function returns a resource which is a pointer to the database connection. It's also called a database handle, and we'll use it in later functions. Don't forget to replace your connection details.
    <?php
    $username = "your_name";
    $password = "your_password";
    $hostname = "localhost";

    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
    echo "Connected to MySQL<br>";
    ?>

  6. #6
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,734
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Quote Originally Posted by Bionic View Post
    you really need to ignore the above post to use MYSQL or MYSQLI they are depricated in php5.3 adn GONE in php5.4

    if you use mysql(i) you will Never be able to upgrade beyond php 5.3 unless you rewrite your script.
    As I said before that statement is just not true. Traq wrote a very good post on this topic.

    Mysql_connect is deprecated, but not removed in any version of php. Mysqli_connect is actively supported and encouraged and there are no plans to remove it for the foreseeable future. The same is true for PDO. reference scroll down to the comparison chart for the status on each of the three main methods for connecting to MySQL using php, which includes mysql_connect.

    Deadweight's response is perfectly valid.
    Last edited by james438; 09-26-2014 at 01:17 AM.
    To choose the lesser of two evils is still to choose evil. My personal site

  7. #7
    Join Date
    Oct 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
    if (!$link) {
    die('Not connected');
    }


    $db_selected = mysql_select_db('foo', $link);
    if (!$db_selected) {
    die ('database is not selected');
    }

Similar Threads

  1. Connect database from other localhost
    By hemi519 in forum MySQL and other databases
    Replies: 4
    Last Post: 04-20-2012, 07:56 AM
  2. How could i connect Content slider with my news database
    By yashwanth in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 05-04-2011, 12:03 AM
  3. Connect to outside database?
    By liamallan in forum MySQL and other databases
    Replies: 3
    Last Post: 04-21-2010, 03:06 AM
  4. Connect to database over a network
    By fobos in forum MySQL and other databases
    Replies: 2
    Last Post: 12-23-2008, 03:27 PM
  5. use ASP to connect to access database
    By sandra in forum ASP
    Replies: 0
    Last Post: 11-28-2007, 07:14 AM

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
  •