Php/mysql 3rd-First day (i)

Source: Internet
Author: User
Tags install php odbc mysql mysql in php and php and mysql php code unpack
This paper introduces how to build a network database application method by Php/mysql of the golden combination of Web database, PHP is a server-side embedded hypertext Processing language similar to Microsoft ASP, it is a powerful tool to build dynamic website. While MySQL is a lightweight SQL database server that runs on a variety of platforms, including Windows NT and Linux, and has a GPL version, MySQL is considered the best product for building a database-driven dynamic Web site. PHP, MySQL, and Apache are the best partners for Linux platform sites. This tutorial is a 3rd course that is described in detail from installation to application.

Introduction of Php/mysql

You should have heard of open source software (OSS) unless you've been living on Mars for the last 6-8 months. The movement has a tremendous impact and has attracted the attention of some big companies. Like Oralce, Informix, and a number of companies are starting to migrate their main database products to one of the products of OSS-the Linux operating system.

If you have enough technical power, having a complex and huge relational database system (RDBMS) is a powerful force. But maybe you're just getting started with the database, and you've just read Jay's article and decided to work on a data-driven Web site. But you may find that you lack the necessary resources to run an ASP server or an expensive database system (and you don't need those things). You need some free, UNIX-enabled stuff.

Then I suggest you use PHP and MySQL. Together, these two things are the best combination for developing data-driven Web sites. In fact, I don't have to bother to explain. The number of hosts applying PHP jumped from 7,500 units in June 1998 to 410,000 in March 1999, according to an unofficial survey organized by Netcraft. Nice, huh? The combination of the two software also won the annual Database Product award at the Webcon98 conference, and won a beautiful trophy.

MySQL is a small and long database server software, for small (and not necessarily very small) application system is very ideal. In addition to supporting standard ANSI SQL statements, it supports a wide variety of platforms, while on UNIX systems the software supports multithreading and can achieve fairly good performance. For users who do not use UNIX, it can be run as a system service on a Windows NT system, or run as a normal process on a Windows 95/98 system.

PHP is a scripting language for server-side interpretation. If you have contacted ASP, you should be more familiar with embedding code in HTML pages. The PHP code is interpreted at the end of the server into a normal HTML page content and sent to one end of the browser. This pattern allows us to use it to perform quite complex functions.

In addition to the free one (of course, MySQL also has some restrictions on licensing), the Php-mysql combination can also run across platforms, which means you can develop on Windows and then run Qiaoqi on UNIX platforms duo Yili HP can also run as a standard CGI process, At this point it is a standalone script interpreter, or an embedded module of Apache.

If you are interested in using a different database server, PHP also supports Informix, Oracle, Sybase, solid, and PostgreSQL, as well as common ODBC.

PHP supports some cutting-edge technologies for Internet development. These technologies include identity authentication, XML, dynamic image generation, WDDX, shared memory, and dynamic PDF documents, among other things. If you are not satisfied, PHP is very easy to expand, so as long as you have the ability to programming, you can do your best.

The last thing to say is that both software are developed by a large number of programmers, so there are many ways to support documents and mailing lists. Bug fixes are fast, and if you ask for a new feature, someone will always consider your request and implement it if the feasibility is high enough.

That's enough! Let's take a look at what's in this tutorial.

The first lesson is about installing both software in a UNIX and Windows environment. If you are not too concerned about this (perhaps you are developing it on your ISP's server), you can skip to the first sample program and start your wonderful journey there.

In the second lesson, we want to learn some more complex scripting features, such as looping, processing user input, and exchanging data with databases, and so on.

The third lesson is about validation and how to make your scripts clear and concise.

Here we go

Second, the installation of MySQL

Move quickly, get these packages, and study it carefully. It's not an easy thing to do. You have a number of options for getting packages, compiling packages, and installing packages. Let's start with MySQL, because it's the only way to run PHP.

The MySQL Central website is For the convenience of people downloading (the software is still relatively large), there are many mirror sites around the world. For more efficient use of the Internet, please find a nearby website to download.

At this time you will also have a variety of options. If you are a fan, you can download the source code, otherwise, there are a variety of platforms on the Internet to run the precompiled binaries can be downloaded directly.

In addition, MySQL has a shared software version for Windows users, with a slightly lower version number. If you want the latest version, you have to pay for a software license. MySQL also provides ODBC drivers that enable front-end applications to access the MySQL database. Some other details are available on its website and you can go and see it.

Pre-compiled versions of UNIX and Windows are simple enough to be used without much explanation. So, let's introduce the source code compilation. Windows users remember that you need to run the MYSQLD program, which is in the Mysql/bin directory.

Download the compressed package file and put it in a directory. Use gzip and tar to decompress and unpack. The quicker approach is to use the following commands:

Gunzip $#@60; mysql-xxxx.tar.gz | Tar xvf-

Where xxxx is a version of your own tag. The above command will create a directory named Mysql-xxxx, all source program files are in this directory. Go to the directory by performing the CD mysql-xxxx command, and carefully read the multiple Readme file install files. These files can be a big help when it comes to some problems.

MySQL comes with some handy configuration scripting programs. Simply type./configure, and you can let these programs do a lot of work for you. If you need to explicitly specify what you want to do, you can use the./configure-help command, which lists the options you can use. For example, if you are compiling on a machine with less memory, you can use the--with-low-memory option. I like to install MySQL in a general directory, rather than installing it in multiple directories on the machine, so I specify the installation directory and specify the-prefix option.

You can also specify many other options, such as what to skip in the compilation, what to keep, and so on. Let's assume that we're all installed in the server's/usr/local/mysql directory. This means that we will type the./configure-prefix=/usr/local/mysql command.

When the configuration script runs, it checks your system, and then generates some files to ensure that the compilation goes smoothly. If the script fails, it also displays some useful error messages that tell you the cause of the failure. You often encounter scripting programs that fail to find multithreaded library files. At this point you should check to see if Mit-pthreads is installed in your system, and if not, install the software. Linux users must install the linuxthreads. These library files are critical for MySQL's multithreaded running mode, which is to run multiple versions of itself.
If all goes well, simply type the make command, and then you can go for a cup of coffee. MySQL is a fairly complex program that can be compiled for a while. If you find an error, you can check the document to see if you have missed some of the preparations that are relevant to your operating system.

Next, type the make install command, and all required files will be installed in the appropriate directory. You're almost ready to start using it! If you are new to MySQL and have never installed MySQL before, you have to create a default permission to install it, so type ... scripts/mysql_install_db to make the appropriate settings.

That's it. Our preparations have been completed. The next thing to do is to start the database automatically when the machine starts and shut down the database automatically when the machine is powered down. Yes, this work also has a special scripting program. The Mysql.server Start command can start the database, and Mysql.server stop can shut down the database. It's just too easy. If you want to start the database manually (so you don't have to reboot the machine), you go to the top-level directory where MySQL is installed (/usr/local/mysql) and type the BIN/SAFE_MYSQLD & command.

We've finished half of it. Next is the PHP section.

Third, the installation of PHP

Well, when I see this, I hope you've installed MySQL and run it. That was so much fun! Here is the PHP ... This process is easier, but the large number of options are dazzling. Of course, you don't have to panic. You can always start over again, recompile PHP, and Add or remove an option as needed.

PHP's home in This site has a huge amount of information, from development project content to software error reporting. As with MySQL, you can choose a mirror to download from your most recent site. Obviously, you get the downloads part of the website to download PHP.

You don't have a lot of choices here. There are some pre-selected binaries, but that's all experimental. If you are not on the Windows platform, download the source code and compile it yourself.

But let's talk about Windows first. When using PHP, it is common practice to develop on a Windows system and then run on a UNIX server. You may end up choosing this approach, which requires you to be familiar with the installation under both platforms.

After you download the Windows binaries, you can extract the files from the package into the PHP3 directory in the C disk with any ZIP decompression program you like. The Readme file in the package gives a partial description of the details of the installation process, but we are here to make a reader's Digest of the key content in this document: If you do not want to install PHP in the C:\PHP3 directory, but other directories, then you have to edit the extracted files in the. inf file.

In the PhP3 directory, you will find many. dll files. Move all of the. dll files that do not start with Php_ to the \Windows\System directory. Then, change the name of the Php.ini-dist file, change it to Php3.ini, and move it to the \ Windows directory. If you open this file, you will find that there are a lot of interesting things can be changed. Now, put the containing:


The comments on the line of content are removed.

If you are using the Apache server on the Win32 platform, set up Apache so that it can identify and interpret PHP files. You need to add the next line to the http.conf file or srm.conf file (depending on which file you are using the version of the Apache software):

Action application/x-httpd-php3 "Php3/php.exe" AddType application/x-httpd-php3. php3

Or, if you are using IIS, right-click the Php_iis_reg.inf file and choose Install. You will have to reboot the system to make the changes you have just made effective.

OK, Finish windows, and then say UNIX. Of course, we're going to start compiling from the source code. Similar to MySQL, download and unpack the source files. PHP also contains a configuration script, but you cannot use the default settings entirely. Run./configure-help | More commands, you can see what new, interesting options are available on a per page basis. You must choose whether to compile PHP into an external CGI program or an Apache inline module. If you are using the Apache Web server and you can recompile it, choose the inline module, which is faster and easier to use. Otherwise, you can choose the CGI method. In addition, you have to specify that the support portion of MySQL will be compiled.

We now assume that you want to compile within the nested module and have the MySQL Support section. If you later need to add additional options or library files, you can add them later. Type the following command:


If you intend to compile with an external CGI program, please remove the-with-apache option. When the configuration program is run, the appropriate system files are created. The next step is to simply execute the make command.

You can have a cup of coffee again. If you feel restless at this time, don't worry. Everyone has a bit of a close feeling when they first install PHP. Just drink some more coffee.

If you choose a CGI program to compile, then you can use it now. Just copy the resulting executable file to the CGI program directory. If you are compiling using the Apache inline module, perform the make install command and copy the files to the Apache directory. In this directory, you can follow the Apache documentation instructions, add PHP modules to it, and recompile Apache.

Now you have to tell the Web server how to process the page content through a PHP program. If you're not using Apache, you'll need to look up the documentation for the Web server software to see how to get it to handle a file with a suffix of. PhP3. The apache1.3.x version of the user should only be included in the httpd.conf or srm.conf file: AddType application/x-httpd-php3.php3. If you're using a CGI program, you'll have to add the following in front of AddType:

Action application/x-httpd-php3 "Php3/php.exe

That's it. Your luck is not so bad, now MySQL is also running, PHP is also working properly.

Now that we have done so much, we can practice the drill below.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.