Results 1 to 8 of 8
  1. #1
    RonR Guest

    Default Connecting to database.

    Connecting to database.

  2. #2
    Rabb Guest

    Default

    Opening a connection to MySQL database from PHP is easy. Just use the mysql_connect() function like this
    <?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'password';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

    $dbname = 'petstore';
    mysql_select_db($dbname);
    ?>

  3. #3
    SJAY Guest

    Default

    If you are reading this page then I shall assume that you already know a little bit about ASP and running ASP applications.
    To make this tutorial more interesting and the following database tutorials on, Adding, Deleting, and Updating, data from a Microsoft Access database, we are going to use these tutorials to make a simple Guestbook application.
    Before we can connect to a database we need a database to connect too.

  4. #4
    Sakio3434 Guest

    Default

    To create a database your first need to open Microsoft Access and choose 'Blank Access Database' from the starting menu. You will be prompted for a name for the database and where you want it saved. Call the database 'guestbook.mdb' and save it in the same directory as the web page connecting to the database is going to be.

  5. #5
    TomLee Guest

    Default

    <?php
    $myServer = "localhost";
    $myUser = "your_name";
    $myPass = "your_password";
    $myDB = "examples";
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");
    $selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");
    $query = "SELECT id, name, year ";
    $query .= "FROM cars ";
    $query .= "WHERE name='BMW'";
    $result = mssql_query($query);
    $numRows = mssql_num_rows($result);
    echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

    while($row = mssql_fetch_array($result))
    {
    echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
    }
    mssql_close($dbhandle);
    ?>

  6. #6
    WooHoo88 Guest

    Default

    The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection can be used against any Microsoft Access database on your web site.
    If you have a database called "northwind.mdb" located in a web directory like "c:/webdata/", you can connect to the database with the following ASP code:
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open "c:/webdata/northwind.mdb"
    %>
    Note, from the example above, that you have to specify the Microsoft Access database driver (Provider) and the physical path to the database on your computer.

  7. #7
    WWF_Champ Guest

    Default

    Create an ODBC Database Connection
    If you have an ODBC database called "northwind" you can connect to the database with the following ASP code:
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Open "northwind"
    %>
    With an ODBC connection, you can connect to any database, on any computer in your network, as long as an ODBC connection is available.

  8. #8
    WeeLi Guest

    Default

    We are going to use the Northwind database in our examples.
    First, import the "System.Data.OleDb" namespace. We need this namespace to work with Microsoft Access and other OLE DB database providers. We will create the connection to the database in the Page_Load subroutine. We create a dbconn variable as a new OleDbConnection class with a connection string which identifies the OLE DB provider and the location of the database. Then we open the database connection:
    <%@ Import Namespace="System.Data.OleDb" %>

    <script runat="server">
    sub Page_Load
    dim dbconn
    dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
    data source=" & server.mappath("northwind.mdb"))
    dbconn.Open()
    end sub
    </script>

Similar Threads

  1. Connecting Eurotherm 6100A to Scheider Quantum
    By moDBus in forum Communications
    Replies: 0
    Last Post: November 2nd, 2011, 07:32 AM
  2. Benefit of wrapping database calls into MTS transactions
    By JIM in forum Programming Languages
    Replies: 2
    Last Post: October 21st, 2010, 08:22 AM
  3. Replies: 3
    Last Post: October 16th, 2010, 11:29 AM
  4. Replies: 0
    Last Post: October 16th, 2010, 09:44 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
  •