This Season
 

PHP SQL Tutorial

PHP is a programming language of the Internet. Part of creating dynamic pages is using SQL in PHP to retrieve data from the server. This code is produced in the PHP pages where it calls the database server. A typical choice for database servers using PHP is MySQL, a free database application available to download. Some web hosts offer MySQL for free with their service.

Related Searches:
    1. Setup the Database Connection

      • To call MySQL from PHP, make a connection string in the application. The best practice for creating a username and password in MySQL is to make only one user for the PHP web pages. This creates better security for the administrator. If the username for the PHP pages is hacked, then the administrator can change that one user's password without the need to change multiple profiles. The username and password is needed for the application. The following code sets up the connection to the MySQL database in PHP:

        $username = "my_user";
        $pass = "pass";
        $database="myDB";
        mysql_connect(server,$username,$pass);
        @mysql_select_db($database) or die( "Could not connect to the MySQL server");

        The first three lines are strings that setup the connection's username, password and database name. The server name is indicated in the connection call named "mysql_connect" in the code. Finally, the last line is the call to the database for a connection. If the connection is unable to be made from a bad server name or username and password, the application prints the "die" message.

      Calling MySQL with a Query

      • Once the connection has been made, the application can send a query to the MySQL server. A query is made using a string, but the query must follow standard MySQL syntax. Below is a sample query used to retrieve data from the database:

        $myquery = "select customer_name from customer";
        mysql_query($query);
        mysql_close();

        The first line is a string character that sets up the query. The query is very basic, retrieving a list of customers from the customer table. The second line actually calls the database and retrieves the information. Finally, the close function is called to close the database connection. This is an important part of performance since connections that aren't closed take up memory on the host server and can slow down an application.

    Related Searches

    References

    Read Next:

    Comments

    You May Also Like

    • PHP & My SQL Training

      PHP is a popular server-side Web scripting language. It's used to add a wide range of programming functionality to websites and can...

    • MySQL PHP Query Tutorial

      You can use PHP to send queries to a MySQL database. PHP must be configured to use the MySQL client libraries during...

    • Dynamic SQL Tutorial

      Dynamic SQL is a programming approach that allows you to create SQL statements dynamically at runtime. Via Dynamic SQL statements, you can...

    • Free SQL Server Tutorial

      Microsoft SQL Server is a database management program with an optional visual interface called Management Studio. SQL Server Express has many of...

    • Advanced Mysql PHP Tutorial

      PHP and MySQL are two open-source software technologies used to manage websites. PHP controls all the server-side programming that affects how a...

    • SQL Server 2008 Report Builder Tutorial

      Report Builder is a part of the SQL Server 2008 Reporting Services offered by Microsoft for the end-users who are not familiar...

    • Beginner SQL Database Connection Tutorial

      Creating a SQL connection is fairly straightforward, whether you are on the command line or accessing a database from a program. The...

    • MS SQL Server Client Tools

      MS SQL Server Client Tools. Microsoft SQL Server is a database package released by Microsoft. Commonly abbreviated as MS SQL, Microsoft's server...

    • Google SQL Tutorial

      Google Query Language, or GQL, is the SQL-like language built into Google's free "App Engine" Web platform. In most respects, its syntax...

    Follow eHow

    Related Ads