Results 1 to 2 of 2

Thread: Open a Connection to the MySQL Server

  1. #1
    Join Date
    Apr 2005
    Posts
    46,704

    Default Open a Connection to the MySQL Server

    Store the connection in a variable ($con) for later use in the script:

    <?php
    // Create connection
    $con = mysql_connect("dbhost", "dbuser ", "dbpass ", "dbname");

    // Check connection
    if (mysql_connect_error())
    {
    echo "Failed to connect to MySQL: " . mysql_connect_error();
    }
    ?>
    Last edited by minisoji; 02-14-2014 at 07:39 AM.

  2. #2
    Join Date
    Apr 2005
    Posts
    46,704

    Default

    Close a Connection


    <?php
    $con = mysql_connect("dbhost", "dbuser ", "dbpass ", "dbname");

    // Check connection
    if (mysql_connect_error())
    {
    echo "Failed to connect to MySQL: " . mysql_connect_error();
    }

    mysql_close($con);
    ?>
    Last edited by minisoji; 02-14-2014 at 07:30 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
  •