1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

connection String Php with Mysql..?

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

  1. tripathi123

    tripathi123 Banned

    help me ....
     
  2. shabbir

    shabbir Administrator Staff Member

    What kind of help?
     
  3. pein87

    pein87 New Member

    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