connection String Php with Mysql..?

Discussion in 'MySQL' started by tripathi123, Oct 1, 2011.

  1. tripathi123

    tripathi123 Banned

    Joined:
    Oct 1, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    help me ....
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,376
    Likes Received:
    388
    Trophy Points:
    83
    What kind of help?
     
  3. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    Php doesn't use connection strings like ASP.NET does. Instead you need to use two functions to establish a connection to both the database and the table.

    PHP:
    $C mysql_connect("localhost","username","password");
    The arguments to the function are the host,username, and password.

    You can check if there is a connection like so

    PHP:
    if($C)
    {

    echo 
    "connection made";

    }
    else
    {

    echo 
    "no connection";

    }
    PHP:
    $DB mysql_select_db("database",$C);
    this function takes the database name and the connection resource(i.e the variable used for the connection function). However by default it uses the last connection resource if available.

    As with the connection function you can use an if statement to check if the variable has any value.

    PHP:
    if($DB)
    {

    echo 
    "database selected";

    }
    else
    {

    echo 
    "database not selected";

    }
    From here you can use mysql_query() to send queries to the database and use the many return function to retrieve some data back from the database for displaying.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice