+ Reply to Thread
Results 1 to 2 of 2

Thread: Connect to database

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    17

    Connect to database

    How do i connect to a database in php ?
    Last edited by jemmy; 11-12-2012 at 02:28 AM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    41
    In this tutorial i`ll be showing you how to connect to a database.

    The Parameters :
    Code:
    mysql_connect(servername,username,password);
    Connect :
    Code:
    <?php
    $con = mysql_connect("127.0.0.1","uname","mypassword");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    // some code here
    ?>
    Close Connection :
    Just add :
    Code:
    mysql_close($con);
    So the code becomes :
    Code:
    <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    // some code here
    
    mysql_close($con);
    ?>

+ Reply to Thread

Tags for this Thread

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