📄 00000096.htm
字号:
performance hit, I usually set up the server to interpret anything with <BR> the .html suffix as PHP. <BR> Now you can just create a file containing some HTML markup and some PHP <BR> code and save it to a file with the suffix that Apache will identify as a <BR> (potential) PHP file: <BR> <BR> <TITLE>Test page</TITLE> <BR> <BR> Hello there, this is my test page <BR> <BR> and today is <BR> <BR> <?PHP <BR> <BR> echo date("l F d Y"); <BR> <BR> ?> <BR> If you make a mistake, the PHP parser will output an error message to your <BR> browser and tell you in what file and on what line it detected an error. <BR> You can also configure PHP to issue warnings when you're about to do silly <BR> things, like using the values of variables before they have been <BR> initialized. <BR> Once your projects start to grow in size it is a good idea to put pieces <BR> of code that you use often into separate files and then use the include() <BR> command to load the code you need. Not only does this encourage code <BR> reuse, but it will also make your HTML files considerably smaller and more <BR> readable. An added bonus is that this will allow you to write less code in <BR> the long run and make it considerably easier to correct your bugs. <BR> To automate inclusion of often used libraries and code you can use the <BR> configuration directives php3_include_path, php3_auto_prepend_file, and <BR> php3_auto_append_file to make PHP load the appropriate libraries for you. <BR> As duly pointed out again and again by the critics of PHP, it is not a <BR> general-purpose language like Perl and thus lacks the immense number of <BR> features and libraries available for Perl. Nor does it have the ability to <BR> com of DBI is to <BR> provide a consistent set of methods and properties that the developer can <BR> use to access databases with different native APIs. <BR> The actual database communication is done by dispatching calls from the <BR> DBI layer to database-specific driver modules, called DBDs. In order to <BR> support a new database you need only install the appropriate DBD module or <BR> if none exists for your database; perhaps develop your own. <BR> In any case, to users of mod_perl this means that whatever database the <BR> DBI interface supports, you can use it in Apache as well. At startup you <BR> can have mod_perl load the DBI interface and on most systems the processes <BR> in the Apache server pool will be able to share the code so you won't have <BR> to waste memory loading DBI in each child. <BR> Persistent Database Connections <BR> Another advantage of using mod_perl in conjunction with DBI is that you <BR> can create persistent connections to the database thereby avoiding the <BR> need to connect and disconnect from the database for every request that <BR> you serve. <BR> To use persistent database connections you should install the Apache::DBI <BR> module. After this is done you simply add PerlModule Apache:: DBI to your <BR> configuration file before any of the modules that actually use DBI. The <BR> reason you have to load this module before any module that uses DBI is <BR> because the DBI package checks to see if Apache::DBI has been loaded. The <BR> Apache::DBI module stores database handles in a global hash and ignores <BR> any attempts to close the connection to the database. <BR> The connections are on a per-server basis, that is, the persistent <BR> connection is established the first time each Web server process makes a <BR> connection to the database. If you try to initialize a database connection <BR> in the parent process of the Web server you may run into a lot of trouble <BR> when several child processes try to access the same database connection at <BR> the same time. Therefore, make sure you do not load any code that opens up <BR> database connections using PerlRequire or PerlModule in the Apache <BR> configuration files. <BR> The Apache::DBI package also comes with some convenient modules for using <BR> databases in authenticating users. This is a neat alternative to the <BR> primitive password files or the somewhat awkward DBM files. <BR> PHP and mod_perl are equally well suited to database connectivity your <BR> choice should be based more on the degree of support that the package has <BR> for your database and what language you are more comfortable with. The <BR> advantage Perl has over PHP is that Perl has a more uniform interface <BR> (remember DBI) to databases and it is probably easier to change database <BR> brands without having to rewrite the code. (Then again, databases are <BR> diverse critters so it may even be worse: You may even have to redesign <BR> your application because the new database does things <BR> differently—regardless of whether you use PHP or Perl) <BR> Embedding Perl in HTML <BR> You can also embed Perl code in HTML documents as you could in PHP. This <BR> is done using the HTML::Embperl package. This package not only offers <BR> embedded Perl in HTML documents for serving pages on-the-fly, but also the <BR> ability to generate static HTML files that can later be served without the <BR> need to run Perl scripts. The latter option may be an alternative if your <BR> content changes at regular intervals, say once per day. <BR> Using HTML::Embperl to embed Perl code in HTML documents is a bit <BR> different than using PHP. When you used PHP you only needed to put <?PHP <BR> and ?> around your code. With HTML::Embperl you have the following ways of <BR> embedding code: <BR> [+ Perl code +] replaces the code inside the [+ and +] marks with the <BR> result of evaluating the Perl code. You can use variables, expressions <BR> and even arrays and hashes. <BR> [- Perl code -] will execute the command inside the brackets, but no <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -