在Google App Engine中使用PHP和MySQL

文章来自于http://docs.google.com/Doc?id=dhg923vj_2ghr8q9f3#PHP

Overview
jiql is a JDBC wrapper for accessing Google DataStore on Google App Engine for JAVA.
jiql supports the use of standard SQL as a method for accessing
the DataStore
Architecture
jiql introduces a concept called "Table Leafs". Table Leafs
are DataStore Kinds that can be dynamically added or
chained together in infinite amounts to represent a Table.
Table Leafs provides a standard method, with SQL, to
retrieve entities of more than the "1000 limit" at a time.
For optimization, entities in the same Table Leaf, has
the same entity group parent. That means all of the
members in the Table Leaf, are located in the same
network node of the Google DataStore Cloud, for faster
access.
To disable Table Leaves, add the following at the end of the
CREATE TABLE statement:
tableleafs=false
Quickstart
Download jiql.jar java database engine and driver library and place under WEB-INF/lib/
NOTE: The appengine-api.jar must also be placed under WEB-INF/lib. This file comes
with the GAE SDK. Follow the steps below to create a JDBC connection with jiql on
GAE-J in your JAVA code:
String url = "jdbc:jiql://local";
String password = "";
String user = "";
Properties props = new Properties();
props.put("user",user);
props.put("password",password);
Class clazz = Class.forName("org.jiql.jdbc.Driver");
Driver driver = (Driver) clazz.newInstance();
Connection Conn = driver.connect(url,props);
Below is the link to a GAE-Ready JDBC guestbook application:
After downloading jiql-jdbc-guestbook.war, unpack to your GAE Application directory.
Edit the ./WEB-INF/appengine-web.xml file and add your GAE Application ID.
Upload to Google App Engine for JAVA.
You must first run the following JSP, which will create the Database table.
http://yourapp.appspot.com/init.jsp
to start using the JDBC guestbook application.
The source code may also be downloaded at the following URL:
Remote Access
You can access Google DataStore from a remote client via the JiqlServlet.
This requires setting up the GAE-J Server as well as the Client Application configuration.
GAE-J Server Configuration
First configure the JiqlServlet in the web.xml like so:
<servlet>
<servlet-name>jiqlservlet</servlet-name>
<servlet-class>org.jiql.JiqlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jiqlservlet</servlet-name>
<url-pattern>/jiqlservlet</url-pattern>
</servlet-mapping>
Next add authenication information in the jiql.properties file:
File: ./WEB-INF/jiql.properties
Entries:
user=admin
password=jiql
Client Application Configuration
Follow the steps below to create a JDBC connection with jiql on the Client in your JAVA code:
String url = "jdbc:jiql:https://yourapp.appspot.com/jiqlservlet";
String user = "admin";
String password = "jiql";
//or
//String url = "jdbc:jiql:https://yourapp.appspot.com/jiqlservlet?user=admin&password=jiql";
Properties props = new Properties();
props.put("user",user);
props.put("password",password);
Class clazz = Class.forName("org.jiql.jdbc.Driver");
Driver driver = (Driver) clazz.newInstance();
Connection Conn = driver.connect(url,props);
Required Libraries for Remote Client
jiql.jar
appengine-api.jar
Apache Commons HTTPClient - you may download the bundled JAR here .
Transactions
jiql has limited support for Transactions.
Transactions support is based on the Google DataStore Transaction
engine. Google DataStore does not support Global Transactions.
A Transaction is limited to Entities/Rows within a Group or Table/Kind.
This mean you are not able to perform operations on multiple
Tables/Kinds within the same Transaction. To enable Transactions,
set the enable.transactions Connection property option to true.
NOTE: Transaction are NOT supported for Remote connections.
Limitations
FILTERS
For large data sets, the left most filter, should not return
a result set of more than about a couple thousand items.
A timeout may result. In this case you should try a narrower
filter. If the query is comprised of multiple filters, you may
place the filter that returns the least items, to the left of all
the other filters.
JOINS
When working with large data sets, JOINS should be combined with
at least 1 filter acting on a specific table. Otherwise, the query would
involve traversing the entirety of all the tables in the JOIN. Such
an operation is time consuming and may create a Google App Engine Timeout
if the operation exceeds 30 seconds.
Optional Properties
date.format
Specifies the Date Format of a DATETIME field.
e.g. date.format=yyyy/MM/dd
enable.transactions
Enable Transactions (please refer to the Transactions topic)
e.g. enable.transactions=true
DatabaseProductVersion
Used to emulate other Databases, such as MySQL.
e.g. DatabaseProductVersion=4.0.0
DriverVersion
Used to emulate other Databases, such as MySQL.
e.g. DriverVersion=mysql-connector-java-5.0.4 ()
Catalog
Used to specify a Database Catalog.
e.g. Catalog=jiql
MetaCache
Used for Caching MetaData, such as DatabaseMetaData.
e.g. MetaCache=true
jiql Functions
In addition to standard SQL functions, there are a number of jiql specific functions.
LOAD
LOAD DATA INTO TABLE table_name INTEXT column1,column2
1,'text1'
2,'text2'
tableleafs
specify whether to use Table Leafs or not (default true).
tableleafs =false
prefix
specify whether to add a prefix to Tables created by jiql (default true)
prefix =false
prefix_value
specify whether to add a customized prefix name to Tables created by jiql (default jiql)
prefix_value =jiql
PHP
How to run PHP with your same MySQL queries
Running PHP on Google App Engine for JAVA requires jiql with a modified version of Quercus ,
a Java implementation of PHP 5. The following URL has the downloads:
jiql-quercus.war - The modified Quercus Application bundled with jiql.
jiql-quercus.src.zip - The modified Quercus source files.
After downloading jiql-quercus.war, unpack to your GAE Application directory.
Add your PHP files to the root of the unpacked Quercus application.
Edit the ./WEB-INF/appengine-web.xml file and add your GAE Application ID.
Upload to Google App Engine for JAVA.
Below is a simple PHP application from PLUS2NET as a starting PHP example:

你可能感兴趣的:(PHP,mysql,jdbc,Google,GAE)