PHPLatest PHP Information. PHP software for Servers, Desktops, Tablets, Mobile Phones. php News.
|What is PHP ? What is PHP ?|
|Resources Libraries and Resources|
|PHP Tutorials Tutorials|
|Tools - Scripts and Tools|
|Websites - PHP Links and Websites|
|Publications and documentation - Articles, Books and Magazines|
|PHP MySql Windows - Advanced Tools for this database|
|This is a guide to setup your own Windows e-commerce site. |
Apache, PHP, and MySQL are excellent tools to build an e-commerce Web site with database connectivity. Here you will learn how to install and configure Apache, PHP, and MySQL on Windows in few easy steps.
| Download PHP |
|Apache .: Installing and Configuring|
|Download Apache |
Download Apache to your hard drive, and run the executable file. Choose the “typical” install.
You can edit it with any editor like Notepad.
# The lines starting with # means that they are commented.
Most of the lines are commented; and other few lines of code are left uncommented.
To uncomment just Remove the "#" from the start of the line.
Start Apache from the start menu and open your Web browser with "http://localhost/" You must see the default installation page to verify that it's working.
The ServerName does not have to be “localhost”, and if you happen to have a real host you can supply its name instead. If you used a real ServerName instead of the default localhost, type that name in the location bar instead. -
Configure the name with the directory location of your website. Search for a line starting with:
|Change the whole group so it resembles the following:|
Options FollowSymLinks ExecCGI
Allow from all
|PHP.: Installing and Configuring
||Download MySQL |
Extract the contents to C:\php
Rename the file called "php.ini-dist" to "php.ini" and move it to C:\WINDOWS or wherever the rest of your *.ini files live.
Copy the two files "Msvcrt.dll" and "phpts.dll", to C:\WINDOWS\SYSTEM
Change apache httpd.conf
ScriptAlias /cgi-bin/ "C:/Apache/cgi-bin/"
Add another ScriptAlias line to the end, just like this:
ScriptAlias /php/ "C:/php/"
Now find a section that looks like this:
#AddType application/x-httpd-php3 .phtml
#AddType application/x-httpd-php3-source .phps
Change the section should now look something like this:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Search for the following line:
# Format: Action handler-name /cgi-script/location
You need to include an Action line for your new file types, so that they are automatically sent through the PHP parser. To do this add the following line:
Action application/x-httpd-php /php/php.exe
Save your httpd.conf file and start Apache again.
There's one good way to test your installation: use the phpinfo() function. Open a text editor and type this:
<? phpinfo() ?>
Save this file as phpinfo.php, and put it in C:website, then fire up your Web browser and go to "http://localhost/phpinfo.php" where you should see a long page of variables and their values. The phpinfo() function produces this page, which shows you your environment and your settings. This tells you that both Apache and PHP are installed and functioning correctly.
|Download MySQL |
See below to download MySQL. The installation itself is very fast and does not require any special modifications. Just follow the installer and restart the computer. Start your web server (Apache) and familiarize yourself with MySQL. I’ll assume you know enough about SQL to understand the statements for creating tables and populating the database. The queries are going to be very simple - the goal is to learn how to manipulate the database using PHP.
|Connecting to and creating a database |
To create a database in MySql you have two choices: use DOS command prompt statements or use PHP code.
From a DOS prompt window switch to MySQL’s bin directory by typing:
(assuming MySql was installed on drive C). To create a database in MySql you will have to type the following:
|mysqladmin –u root create roll
||This will create a database called “roll”.
In PHP we will use mysql_create_db () function to create the database.
|If (mysql_create_db (“ roll ”, $link ))|
print (“ The database, roll, was successfully created!<BR> ”);
print (“ The database, roll, could not be created!<BR> ”);
|Obviously, you’ll have to provide the database name and the link to MySql obtained using the mysql_connect() function:
||$link = mysql_connect (“ localhost ”, “ root ”);
||To close the link we will use the mysql_close() function.
||Unless you have logged in using a user account that does not have administrative privileges, this should work without any problems. The dump file used for the database will contain the following statements:
||create table person |
personId int auto_increment not null,
firstName varchar(20) not null,
lastName varchar(20) null,
insert into person values(1, 'john', 'doe', 'firstname.lastname@example.org');
insert into person values(2, 'jeff', 'bridges', 'email@example.com');
|A dump file is an SQL script file. It contains well-formed SQL statements; it is preferable to the command line because it is easier to debug and reload if it contains errors. Dump files should be placed in MySQL’s bin directory. Load that up to the database by typing the following:|
mysql –u root roll < roll.dump
|Now you should have a database that’s ready to use. I suggest using a text editor that will preserve line wrapping like Notepad. Lets start with some simple PHP statements. PHP code can be inserted just about anywhere into your HTML code, or replace HTML altogether.
||First of all you will need to connect to your database so we will use the following statement:|
$link = mysql_connect (“localhost ”, “ root ”);
|The statement was written under the assumption that you are logged in as the root user. Now that you are connected, you will need to select a database with the following statement:|
mysql_select_db (“roll”, $link);
|Retrieving Data From A Database
||Lets write a simple query:
||$result = mysql_query(“ SELECT * FROM person ”, $link );
||The result of the query will be stored in the variable $result. To run a query on the database we can also use the mysql_db_query() function. The first parameter is the database name, second is the query string in SQL format, and the third is the link to the database.
||mysql_db_query(“ databaseName ”, $Query , $link )
||Again, we can use an if/else control structure to display errors during execution, which can be helpful for debugging.
||Now you have a basic understanding of how to create, populate, and retrieve information from a MySQL database using PHP. Feel free to modify the PHP file and insert it into or delete it from the database. For more information on other options to try, there’s plenty of online documentation available at www.php.net and other sites on the Web.