设为首页 收藏本站
查看: 366|回复: 0

[经验分享] 在Google App Engine中使用PHP和MySQL

[复制链接]

尚未签到

发表于 2016-10-18 07:35:18 | 显示全部楼层 |阅读模式
  文章来自于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:
http://jiql.googlecode.com/files/jiql-jdbc-guestbook.war

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

Then browse to http://yourapp.appspot.com/guestbook.jsp
to start using the JDBC guestbook application.


The source code may also be downloaded at the following URL:
http://jiql.googlecode.com/files/jiql-jdbc-guestbook.src.zip


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.transactionsConnection 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 Transactionstopic)
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,column21,'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:
http://www.plus2net.com/php_tutorial/guest_book.zip

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-287647-1-1.html 上篇帖子: 百万级高并发网站MYSQL应用攻略 下篇帖子: MYSQL 大量文本查询 解决方案-fulltext索引
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表