As? Weallknow, either SAE or BAE, does not support connecting to external databases. Only cross-application access is supported. Whether it is for business or security considerations, database closures are more or less regrettable for platform vendors. In particular, some individual developers like to go to various servers, so it is very convenient to have a unified database. Sufficient
As? We all know, either SAE or BAE, do not support connecting to external databases. Only cross-application access is supported. Whether it is for business or security considerations, database closures are more or less regrettable for platform vendors. In particular, some individual developers like to go to various servers, so it is very convenient to have a unified database. Sufficient
As? We all know, either SAE or BAE, do not support connecting to external databases. Only cross-application access is supported. Whether it is for business or security considerations, database closures are more or less regrettable for platform vendors. In particular, some individual developers like to go to various servers, so it is very convenient to have a unified database. You can make full use of the advantages of each platform for development and migration.
Here comes my RemoveMysql. Cross-database access is achieved through interfaces. RemoveMysql is only suitable for small-scale development. When the data volume is large, it is severely restricted by the network environment and may suffer severe latency. Therefore, we recommend that you use small applications instead of big application environments. For large applications, you are advised to write a complete REST Server, or change to a remote Server that supports traditional access to the database. By the way, pay attention to website security when using RemoveMysql, and change the code file name and communication key to improve security.
: Http://code.google.com/p/remove-mysql/downloads/list
After the download, there are two folders. Dbclient is a local client and Dbserver is a server. Their relationship is that Dbclient accesses the database on Dbserver. For example, you can place Dbclient on an application of SAE and Dbserver on an application of BAE. Through configuration, the SAE application can access the BAE database. The opposite is true. The following describes how to configure it.
1. Configure Dbserver
The Dbserver folder has only one single file named index. php. The file starts with a $ config array and stores configuration information. You need to fill in the necessary information according to the actual situation. Includes the Communication Key (which is customized by you and used by Dbclient), database server address, port, and so on. For a common php space, cpanel is generally written on the rear panel. Let me talk about SAE and BAE.
For SAE, the database information is predefined as a constant, so it can be very unified. You can directly copy the following information (except the communication key)
$ Config = array ('secret' => 'your _ secret', // enter the Communication Key 'host' => SAE_MYSQL_HOST_M, // database server address 'Port' => SAE_MYSQL_PORT, // database server address port, 'username' => SAE_MYSQL_USER, // database username 'Password' => SAE_MYSQL_PASS, // Database password 'dbname' => SAE_MYSQL_DB, // select the database 'charset' => 'utf8' // encoding. The default value is utf8 );
For BAE, It is similar. The following is for your reference.
$ Config = array ('secret' => 'your _ secret', // enter the Communication Key 'host' => getenv ('HTTP _ BAE_ENV_ADDR_ SQL _IP '), // database server address 'Port' => getenv ('HTTP _ BAE_ENV_ADDR_ SQL _PORT '), // database server address port 'username' => getenv ('HTTP _ bae_env_ak '), // database username 'Password' => getenv ('HTTP _ BAE_ENV_SK '), // Database password 'dbname' => 'awdudinfgjfckudvdhm ', // obtain the name of the database to be connected from the platform: 'charset' => 'utf8' // encoding. The default value is utf8 );
In particular, the 'dbname' entered above should be queried from the BAE background. Pay attention to the correct database encoding. I do not know whether the default BAE encoding is GBK or not. In short, it can be modified through the background.
2. Use Dbclient
Index. php is a simple call example. New Mysql () requires two parameters: url and Communication Key. The url is the address of your Dbserver, and the communication key is the 'secret' defined on the Dbserver '. For detailed method calls, see the source code and comments of MysqlClient. class. php. If the encapsulated methods are not enough, you can add several operations that meet your actual needs.
Original article address: remote connection to the database using php code, which enables mutual access between the BAE and the SAE database. Thanks to the original author for sharing.