GAE PHP Lose connection with mongodb - php

I am building PHP app with codeigniter and using GAE with Mongodb. GAE is billing enabled but the connection to mongo is not stable and it drops 1/4 when the app is online, locally works fine with GAE PHP SDK:
php.ini
google_app_engine.enable_functions = "libxml_disable_entity_loader"
google_app_engine.enable_curl_lite = “1”
extension="mongo.so"
mongo_library.php
try {
//connect to the mongodb server
SELF::$mongo_client = new MongoClient($config_data['mongo_connection_string']);
//select the mongodb database
$this->db = SELF::$mongo_client->selectDB($config_data['mongo_database']);
} catch (MongoConnectionException $exception) {
//if mongodb is not connect, then display the error
show_error('Unable to connect to Database', 500);
}
I am using mongo free plan from mongolab.com google cloud provider.
Here is the link where is show My app and where you can see how it fails by refreshing couple of times.
$a = mongo_db::$mongo_client;
$connections = $a->getConnections();
print_r($connections);

Here is the issue I opened:
https://code.google.com/p/googleappengine/issues/detail?id=12392
and this issue/bug is already fixed.

Related

How to connect a Linux server with Wordpress 4.2 server to Azure SQL DB with PHP 5.4?

I have a Linux server running Wordpress 4.2 and I have 2 Azure DB, one is SQL Server and the other is CleanDB.
The Windows Server(s)
Windows 7 Pro/Windows Server 2012 R2 sp1
Visual Studio 2013
SQL Server 2012 sp1
PHP 5.4 WP 4.2
Linux Server
CentOS 6.0
WP 4.2
PHP 5.4.31
It runs on SQL server, visual studio, and my php script on my Windows server to the CleanDB and SQL Server run fine and when I run the connection string on the Linux server to the CleanDB.
It won't connect when I run the Linux server to the SQL server.
I only allowed the DB to allow 4 calls and it isn't pulling.
The IP ranges were added on the firewall.
I used the exact same string in all instances.
I found a few other related questions that some help:
SO References:
Cannot connect to azure db via SqlConnection
"Call to undefined function sqlsrv_connect()" when trying to connect to Azure DB from PHP
MSDN References:
https://azure.microsoft.com/en-us/documentation/articles/sql-database-php-how-to-use/
https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-connect-on-premises-sql-server/
it won't connect when I run the Linux server to the SQL server.
Do you mean you couldn’t connect to SQL Azure from a Linux server while using sqlsrv drive? Please note, SqlSrv is a Windows driver, on Linux we can use PDO_DBLIB drive and PDO_ODBC (not recommend), more detailed info could be found at: http://php.net/manual/en/ref.pdo-dblib.php.
Code snippet via using PDO_DBLIB for your reference:
<?php
$dbHost = 'YourName.database.windows.net';
$dbUser = 'DBUserName';
$dbPass = 'DB Password';
$dbName = 'DB Name';
try {
$pdo = new PDO("dblib:host=$dbHost:1433;dbname=$dbName", $dbUser, $dbPass);
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
Code snippet via using PDO_ODBC for your reference:
$connection = odbc_connect("Driver={SQL Server};Server=$dbHost; Database=$dbName;", $dbUser, $dbPass);
$qry = "SELECT * FROM Clienti";
$result = odbc_exec($connection,$qry);
// Get Data From Result
while ($data[] = odbc_fetch_array($result));
// Free Result
odbc_free_result($result);
// Close Connection
odbc_close($conn);
// Show data
print_r($data);
AS to DB settings, please do not forget to manage allowed IP addresses on Azure portal, i.e. add your client IP address in Allowed IP Addresses section on Azure portal. https://msdn.microsoft.com/en-us/library/azure/ee621782.aspx#Troubleshooting
Feel free to let me know if I have any misunderstood on your issue.

PHP pdo remote connection to Oracle error

I have been trying to connect remotely to oracle using pdo
I have enable pdo driver
extension=php_pdo_odbc.dll
But getting this error
"SQLSTATE[HY000]: OCIEnvNlsCreate: Check the character set is valid and that PHP has access to Oracle libraries and NLS data (ext\pdo_oci\oci_driver.c:614)"
Here is my code for connection
try {
$dbh = new PDO("oci:dbname='My server ip'/orcl;charset=UTF-8", "my user name", "my password");
}
catch (PDOException $e)
{ echo $e->getMessage(); }
I had the same errormessage after I installed multiple copies of ODAC/ODT because I didn't know what version I needed to have my Visual Studio projects (Windows Forms app and a ASP.NET website) connect to a Oracle database. While fixing this connection problem in the end, I broke my PHP/PDO website which also needed to connect to the same Oracle database. It gave me the same errormessage as in your question.
I removed all ODAC/ODT client installations and also the Oracle Server to be sure and then I reinstalled only the Oracle Server (in my case Oracle 11.2 Express 64bit) and it worked again. I could connect again from SQL Developer and also through PHP/PDO. After that I installed the correct ODAC/ODT (32bit(!) version because of my 32bit Visual Studio) and now also my Visual Studio Forms project AND ASP.NET website could connect to the Oracle server.

Connect MySQL (installed through MAMP) to Google App Engine SDK

I am unable to make a database connection from the App Engine SDK server to my local MySQL which was installed with MAMP. I understand that this is about the MySQL socket file which is in MAMP. How can I let App Engine SDK to listen to the local MySQL? I also want to ensure that my MAMP setup remains intact. Thanks.
App engine SDK for php can connect to you local MySql server in your development environment.
First make sure you have the latest SDK for PHP version, currently release 1.8.6.
Make sure your local MySql server instance is running and listening on port 3306.
Add your application in the App Engine SDK Launcher, click on it and select Edit / Application Settings and add in the "Extra Command Line Flags" field the following:
--mysql_user=user
Where user is the username to connect to your database.
Then you have to connect to your DB from your php code, in my case, I'm using PDO.
Like this:
try {
$db = new PDO('mysql:unix_socket=/cloudsql/<appname>:my-cloudsql-instance;charset=utf8;dbname=<yourdbname>','<user>','<password>');
syslog(LOG_DEBUG, 'Connected to database.');
} catch (PDOException $e) {
syslog(LOG_ERR, 'Failed to get PDO DB handle: ' . $e->getMessage());
print_r($e->getMessage());
exit;
}
Replace the text with <> tags with your application and MySql server settings.
GAE currently does not allow connection to any remote MySQL server. This is their limit and nothing to do with your setup.
Use their Cloud SQL instead.
I don't know in which situation the error occurred to Nagarjun, but to me happened with the following PHP warning
Warning: mysql_connect(): No such file or directory in
/Users/Aerendir/Documents/JooServer/_SandBox/GoogleAppEngine/continuous-wordpress-cms/wordpress/wp-includes/wp-db.php
on line 1372
In my situation, i were trying to install WordPress on Google AppEngine following their tutorial.
The problem was the hostname I used: localhost instead of 127.0.0.1
Using 127.0.0.1 as hostname solved the problem.
The solution was found here: Configuring MySQL connection in Google App Engine PHP SDK on Windows 7

How do I connect to external mysql database on heroku?

I created a FB app hosted on Heroku.
Instead of Heroku's database I use a mysql database. I made the chage using this code:
heroku config:add DATABASE_URL=mysql://user:pass#server:port/database_name
So far everything is ok but now I have an issue connecting to the database in my index.php file.
I don't know ho to do.
I tried to connect to the DB as I do on my website
try {
$bdd = new PDO('mysql:host=host;dbname=database_name', 'user', 'pass');
}
catch (Exception $e) {
die('Erreur : ' . $e->getMessage());
}
But I have an error in my app:
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
Thank you
Check whether your remote database port is opened for external connection. Look for bind-address configuration of your remote mysql server.

MongoLab addon PHP app hosted on heroku

I've a PHP app to be hosted on heroku. The basic functionality of the app is to collect some data from users (through browsers) & store those in a database (since this is a PHP app, the database modifications must be made through PHP only). Now I've enabled the MongoLab addon from heroku control panel & created database, user, & sample collection into that database. I've deployed my code to heroku via git. Following is the content of a file db.php located inside the root folder of the app
<?php
try {
$user = 'my user name';
$pass = 'my password';
$app = 'my app name';
$col = 'sample collection';
echo 'connecting ...';
$connection = new Mongo('mongodb://'.$user.':'.$pass.'#ds034512.mongolab.com:34512/'.$app);
echo 'connected';
$database = $connection->selectDB($app);
$collection = $database->selectCollection($col);
}
catch(MongoConnectionException $e) {
die("Failed to connect to database ".$e->getMessage());
}
?>
now whenever I'm trying to execute the file on the heroku server itself (by caling the url http://my-app-name.herokuapp.com/db.php from my local browser) it's showing
"connecting ..." & in the console there is an error message "NetworkError: 500 Internal Server Error - http://my-app-name.herokuapp.com/db.php"
Can anyone suggest me any idea on how this database integration be done for apps hosted on heroku ?
You didn't include the mongodb driver. This gist has all the instructions.
https://gist.github.com/1288447

Categories