Database Articles

  Home arrow Database Articles arrow Page 4 - Creating a Search Application
DATABASE ARTICLES

Creating a Search Application
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 16
    2003-07-15

    Table of Contents:
  • Creating a Search Application
  • Database Usage
  • Creating a Search Application
  • Searching
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Creating a Search Application -


    (Page 4 of 29 )

    In order to connect to a database server, you need to know the hostname of the server, a username, and a password. The hostname is generally localhost because the database server normally resides on the same machine you are running your PHP code on. The following statement will make a connection to a database server.

    <?php
    $db 
    mysql_connect ('localhost''username''password')
          or die (
    "Unable to connect to Database Server");
    ?>

    The function mysql_connect() makes the connection to the database server and returns a resource id, which we are storing in the variable $db. The resource id is an identifier to PHP that references the database connection. This resource id can be used in other MySQL functions to differentiate between multiple database connections.

    One thing you may not recognize is the use of the die function. The die function halts the execution of the script and displays the message passed to it. If we were to translate the above PHP code into English, we would say, "Make a connection to the database server 'localhost', using a username of 'username' and a password of 'password', and store an identifier for that connection in the variable $db. If you are not able to make the connection, stop executing this script and display the message 'Unable to connect to Database Server'.

    Now that we have established a connection to the database server, our next task is to select the database we want to work with.

    More Database Articles Articles
    More By Matt Wade

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap