MySQL Data on the Web

Before we leap forward, it’s worth taking a step back for a clear picture of our ultimate
goal. We have two powerful tools at our disposal: the PHP scripting language
and the MySQL database engine. It’s important to understand how these will fit
together.

The whole idea of a database driven website is to allow the content of the site to
reside in a database, so that content may be pulled dynamically from the database
to create web pages for viewing on a regular browser. So, at one end of the system
you have a visitor to your site using a web browser to request a page. That browser
expects to receive a standard HTML document in return.

Just so it’s clear and fresh in your mind, this is what happens when there’s a visitor
to a page on your database driven website:
1. The visitor’s web browser requests the web page from your web server.
2. The web server software (typically Apache) recognizes that the requested file
is a PHP script, so the server fires up the PHP interpreter to execute the code
contained in the file.
3. Certain PHP commands (which will be the focus of this chapter) connect to the
MySQL database and request the content that belongs in the web page.
4. The MySQL database responds by sending the requested content to the PHP
script.
5. The PHP script stores the content into one or more PHP variables, then uses
echo statements to output the content as part of the web page.
6. The PHP interpreter finishes up by handing a copy of the HTML it has created
to the web server.
7. The web server sends the HTML to the web browser as it would a plain HTML
file, except that instead of coming directly from an HTML file, the page is the
output provided by the PHP interpreter. The browser has no way of knowing
this, however. From its perspective, it’s requesting and receiving a web page
like any other.

Here’s how you use PDO to establish a connection to a MySQL server:
new PDO('mysql:host=hostname;dbname=database', 'username',
'password')
Related Posts:
  • php -Mail Functions The mail() function requires an installed and working email subsystem for sending mail. The program to be used is defined by configuration directives in the php.ini file. A common pitfall is that these are not set up cor… Read More
  • Php tutorial - imagemagick Php tutorial - imagemagick Php tutorial - imagemagick - create, edit and compose bitmap  imagemagick is free software  to create, edit, and compose bitmap images in many formats from the commandline or via progra… Read More
  • Displaying Browser Specific-php However, having seen some of the possible values of HTTP_USER_AGENT in the last chapter, you can imagine that there are hundreds of slightly different values. So it's time to learn some basic pattern matching.You'l… Read More
  • difference between print and echo - php print( ) is a function, echo is a language construct.  This means that print( ) returns a value, while echo doesn't. You can include print( ) but not echo in larger expressions. echo is  run very fast than  … Read More
  • Magic Methods-Php Php Mail Php Array Php If else Php Variable This is a link Php Substrings Php Sessions Magic Methods and Constants Magicmethods are specially named methods that can be defi nedin any class and … Read More
  • PHP identical operator === Variable types are also important in comparison.When you compare two variableswith the identical operator (===), like this, the active types for the zvals are compared,and if they are different, the comparison fails outright… Read More
  • The $_REQUEST Variable-php PHP is a lot more than a way to work with text. You’ve been working with strings non-stop, but there are a lot more types of information you’ll need to work with in your PHP scripts. As you might expect, there are all kinds … Read More
  • socket tcp server with php Php Web Application Php Email Codes Php Array Php Ifelse Php variables Php Substrings Php Mysql Functions php-sessions HTTP is the standard that allows documents to be communicated and shared over &nb… Read More
  • Get mail info with IMAP or POP3 To read mail using IMAP or POP3, which allows you to create a web-based email client. Use PHP's IMAP extension, which speaks both IMAP and POP3: // open IMAP connection $mail = imap_open('{mail.server.com:143}', &nb… Read More
  • Send Email from a PHP Script you use the mail() function (in combination with a web form in particular), make sure you check it is called from the desired page and protect the form with a CAPTCHA mail(to,subject,message,headers,parameters); <?php… Read More
  • Php session Info and cookies #menu111 { BORDER-RIGHT: #cccccc 1px dashed; PADDING-RIGHT: 20px; BORDER-TOP: #cccccc 1px dashed; PADDING-LEFT: 20px; BACKGROUND: #dddddd; LEFT: 20px; PADDING-BOTTOM: 20px; MARGIN: 0px; BORDER-LEFT: #cccccc 1px dashed; WI… Read More
  • Php HTTP Basics Php Web Application Php Email Codes Php Array Php Ifelse Php variables Php Substrings Php Mysql Functions php-sessions Php HTTP Basics When a web browser requests a web page, it sends an HTTP request… Read More
  • Third-party Cookies Third-party Cookies Third-party cookies come from other domain sources that have items, such as ads or images,  embedded on the page adjust cookie and site data permissions. Manage your cookies and site data - chrome … Read More
  • Adding CSS style in php script <?php       echo '<span style="font-size:10px">';    // add  styles as  style attribute       echo 'test';     &nbs… Read More
  • Creating a Simple Php Functions #menu111 { BORDER-RIGHT: #cccccc 1px dashed; PADDING-RIGHT: 20px; BORDER-TOP: #cccccc 1px dashed; PADDING-LEFT: 20px; BACKGROUND: #dddddd; LEFT: 20px; PADDING-BOTTOM: 20px; MARGIN: 0px; BORDER-LEFT: #cccccc 1px dashed; WID… Read More