PHP and MySQL

From Resin 3.0

Revision as of 17:40, 9 January 2006 by Ferg (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Contents

Introduction

This article provides some simple steps so that you can access MySQL from a Quercus / PHP page. It assumes that you have already installed MySQL and that it is running on port 3306. It also assumes that you have already installed Resin and can at least get "HelloWorld.php" to run (see: PHP Hello World).

For the purposes of this article, I assume that you are working with Resin 3.0.17 and that the directory housing httpd.exe is c:\resin-3.0.17. I will call this directory %ResinHome%.

Step 1: Download the MySQL jdbc driver

As of this writing (2-Jan-06), you can download the current MySQL connector/J at http://www.mysql.com/products/connector/j/. Copy the the jar into %ResinHome%\lib.

Step 2: Modify %ResinHome%\conf\resin.conf

Open resin.conf in your favorite text editor and find the following section:

Excerpt from resin.conf

<!--
      - Sample database pool configuration
      -
      - The JDBC name is java:comp/env/jdbc/test
      -
        <database>
          <jndi-name>jdbc/mysql</jndi-name>
          <driver type="org.gjt.mm.mysql.Driver">
            <url>jdbc:mysql://localhost:3306/test</url>
            <user></user>
            <password></password>
           </driver>
           <prepared-statement-cache-size>8</prepared-statement-cache-size>
           <max-connections>20</max-connections>
           <max-idle-time>30s</max-idle-time>
         </database>
     -->

Uncomment the <database> element. For those less comfortable with XML, this means strip out the first 5 lines (from <!-- to -) and the last line (-->).

Step 3: add a <database> element to %ResinHome%\webapps\ROOT\WEB-INF\web.xml

web.xml

<web-app xmlns="http://caucho.com/ns/resin">
  <servlet-mapping url-pattern="*.php"
                   servlet-class="com.caucho.quercus.servlet.QuercusServlet">
    <init>
      <compile>false</compile>
      <database>jdbc/mysql</database>
    </init>
  </servlet-mapping>
</web-app>

Now restart httpd.exe

Conclusion

These steps will allow you to use the mysql and the improved mysql modules from within a quercus page.

Personal tools