Timeout while connecting to mongo database with mongo php ext - php

Timeout while connecting to MongoDB database with mongo php ext under Ubuntu 12.04 and php 5.6
I'm using
latest Apache 2.4
Ubuntu 12.04
php 5.6 with mongo ext Version 1.6.14
MongoDB v3.4 running in an lxc container
And the problem is when I connect to the mongo database.
I'm using this connection string:
mongodb://myDbUser:passW0rT#0.0.0.0:27020/myDb
(password, database and addr have been changed).
I have verified that php mongo ext is installed, with this code:
echo extension_loaded("mongo") ? "loaded\n" : "not loaded\n"; //prints loaded.
if (class_exists('\MongoClient')) {
echo 'is Mongo Client'."\n";//this is printed
}
else {
echo 'no Mongo Client'."\n";
}
try {
$client = new MongoClient('mongodb://myDbUser:passW0rT#0.0.0.0:27020/myDb', []);
} catch (Exception $ex) {
echo $ex->getMessage();//prints Failed to connect to: 0.0.0.0:27020: Connection timed out
}
What is more strange I can connect to this database using MongoClient and in addition to this I can connect to this database by my local server running on my computer (Win 10).
The problem appears also when I use security.authorization set to enabled and without difference set to disabled – then I use dsn mongodb://0.0.0.0:27020
Unfortunately server's response always gives timeout error when I enter web addr using www (domain which is on the server where mongo database is installed).
It could be one clue that server where mongo is installed is server which runs as container which means that I have to add port number to connect eg. via ssh.
I even changed the server from ngix to apache and problem didn't disappear.

Related

PHP Sql Server PDOException:could not find driver

My server is a Windows 2008 server. PHP Version 7.2.7 is installed and running. Sql Server 11 (64 bit) is installed and is working (there is a couple asp.net apps running and already using that database)
I downloaded the PHP Sql Server Drivers from Microsofts website and placed the .dll files in the PHP ext directory.
In my PHP.ini I added:extension=php_pdo_sqlsrv_7_nts_x64
In my .php file I am using to test my db connection I have:
$SqlServer = "THISSERVER\SQLEXPRESS";
$SqlServerCon = new PDO("sqlsrv:server=$SqlServer;Database=TheDatabase", "DbUName", "DbPassword");
if (!$SqlServerCon) {die('Unable To Connect to Sql Server');}
else
{echo "Connection Successful";}
I am getting:
PHP Fatal error: Uncaught PDOException: could not find driver in D:\Inetpub\wwwroot\TechStory2\DBtest.php:7 (Line 7 is the $SqlServerCon line).
What did I do wrong? and What do I need to do to get a connection to Sql Server?
I got it figured out. I had to install the ODBC Driver 17 for SQL Server (msodbcsql_17.2.0.1_x64.msi) on my server. The SQL Server Native Client 11.0 was installed but not the ODBC Driver for SQL Server.
For future reference for anyone else with this or a similar issue...
It can be downloaded at https://www.microsoft.com/en-us/download/details.aspx?id=56567 (note: if you have a 32 bit server, you will want to install the msodbcsql_17.2.0.1_x86.msi - If you accidentally try to install the incorrect version, it will let you know during the installation). After the driver is installed, you need to reboot the server. It won't prompt you to restart, but you'll need to.
In my PHP.ini I have added extension=php_pdo_sqlsrv_72_nts.dll and extension=php_sqlsrv_72_nts_x64.dll They can be downloaded at https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017
More info can be found at https://learn.microsoft.com/en-us/sql/connect/php/loading-the-php-sql-driver?view=sql-server-2017 and https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017
I can now establish a connection to Sql Server using either sqlsrv_connect or PDO.
PDO connection test:
$SqlServer = "THISSERVER\SQLEXPRESS";
$SqlServerCon = new PDO("sqlsrv:server=$SqlServer;Database=TheDatabase", "DbUName", "DbPassword");
if (!$SqlServerCon) {die('Unable To Connect to Sql Server');}
else
{echo "Connection Successful";}
sqlsrv_connect connection test:
$SqlServer = "THISSERVER\SQLEXPRESS";
$DbConnInfo = array( "Database"=>"TheDatabase", "UID"=>"DbUName", "PWD"=>"DbPassword");
$SqlServerCon = sqlsrv_connect( $SqlServer, $DbConnInfo);
if( $SqlServerCon ) {echo "Connection established";}
else
{echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));}
As commentators said - adding .dll at the end of extension= config line should be good start with your issue.
I can also see that you're trying to load NTS version of extension (NTS stands for non thread safe). Are you sure that you're going to load right version of extension? Please check if you're running PHP as NTS runtime or not - you can check it with phpinfo();.

Cannot connect mongoDB and PHP

I am successfully running mongoDB v3.2.10 in terminal on macOS 10.11.6 and MAMP server running php 7.0.8.
When I try to reach mongo via php code like:
<?php
// connect to mongodb
$m = new MongoClient();
?>
at url: http://localhost:8888/Mongo/login.php
I get:
This site can’t be reached
localhost refused to connect.
When I reach mongo on the native port
at url: http://localhost:27017/Mongo/login.php
I get:
It looks like you are trying to access MongoDB over HTTP on the native
driver port.
Any idea what am I missing here?
Looks like you are using the built-in PHP Mongo DB clients. There is a new MongoDB driver that replace that. You will have to install it.
http://php.net/manual/en/set.mongodb.php
The newer MongoDB extension replaces the built-in PHP Mongo DB client. You'll also want to use the composer PHPLIB MongoDB client from here: http://php.net/manual/en/mongodb.tutorial.library.php
use MongoDB\Client;
try {
$mongoDbClient = new Client('mongodb://localhost:27017');
} catch (Exception $error) {
echo $error->getMessage(); die(1);
}

mySQL not working anymore after I updated MAMP

mySQL serveur cannot be connected while apache server works fine. (everything was working fine when I used the previous version of MAMP) Here a message I got when trying to connect
/Applications/MAMP/Library/bin/mysqlcheck: Got error: 2002: Can't connect to local MySQL
server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2) when trying to
connect
By the way when I request an URL in local that does not require any DB connextion its working fine (seems obvious) and when it does require some DB connection I got the following message:
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61)
CONFIGURATION:
MAC BOOK OX S 10.8.5
MAMP 3.0.7.3
php 5.6.2
Symfony2
Remove the files ib_logfileN (N being the number) from the MAMP/db/mysql56 folder then restart your MAMP.
If still not working then also delete the ibdataN (N being the number).

How to connect with sql server using php in xampp

I have xampp install in my computer and xampp php version is 5.5.15 i want to connect with a sql server (which is also install in my computer sql server 2005) i download php driver and copy paste two php file "php_pdo_sqlsrv_55_ts.dll" and "php_sqlsrv_55_ts.dll" in "C:\xampp\php\ext" folder and format php.ini file extension=php_pdo_sqlsrv_55_ts.dll and extension="php_sqlsrv_55_ts.dll" my problem is when i am restart the apache server (from xampp control panel) it's display two error message one is
httpd.exe error "http.exe error msvcp110.dll is missing from your computer"
another one is
"xampp error php startup unable to load dynamic library the specific module could not be found"
beside this error i am trying to connect with sql server using code but the code return with undefined sqlsrv_connect function error
My code is simple
<?php
$serverName='SANTUNU23-PC\SQLEXPRESS';
$connectioninfo=array ('Database'=>'DB2662_cslBeseElec');
$myuser='santunu23';
$conn=sqlsrv_connect($serverName,$connectioninfo);
if($conn)
{
echo 'connection established';
}
else
{
echo 'can not make the connection';
die(print_r(sqlsrv_errors(),TRUE));
}
?>
What to do now?any suggestion My system is windows 7 32bit
You could've googled "msvcp110.dll", then you would know that this file belongs to the "Microsoft Visual C++ 2012 Redistributable Package". So download it, install it, try it again.

MSSQL VIA FreeTDS, ODBC, and Cpanel Unknown host machine name (severity 2)

I have installed FreeTDS 0.91, ODBC, on a Cpanel server running Centos 6.5x64. Everything appears to be running fine and I can connect to the remote MSSQL 2012 server using:
/usr/local/freetds/bin/tsql -S sqlserver -U test -P mypassword
and succesfully execute queries in the database.
I can also connect through:
isql -v sqlserverdatasource test mypasswordhere
But for some reason /usr/local/freetds/bin/tsql -LH server.ip.here
returns no information or errors which doesn't make much sense when it is proven I can connect with the other methods above.
So now when running a test script from a cpanel account on the machine I get:
Unknown host machine name (severity 2)
Here is the test script:
//Database connection function.
function getConnection() {
try {
//$dbconnect = new PDO("sqlserver:Server=server.ip.here,1433;Database=dbname", "user", "password");
$dbconnect = new PDO("dblib:host=server.ip.here,1433;dbname=dbname", 'user', 'password');
} catch (PDOException $e) {
echo "CONNECTION ERROR.<br>Error message:<br><br>" . $e->getMessage();
die();
}
if (!$dbconnect) {
die('Cant connect to database. Please try again later!');
}
else{
echo "i'm in!";
return $dbconnect;
}
}
The first commented line is the old one using sqlserv which I found did not work at all from what i can tell because of the x64 OS. I have also tried with "" around user and pass as well as no marks at all.
php -m does show PDO and pdo-dblib.
Any ideas where I can look next?
Update: This was fixed. I missed in freetds.conf:
[global]
# TDS protocol version
tds version = 8.0
It was originally set to 4.5 instead of 8.
The fix for me was with three steps:
First, I edited /etc/freetds/freetds.conf and changed the tds version like this:
tds version = 8.0
The second step was not entering port number. The port was already 1433, and not specifying it fixed the exact same issue on my case.
Lastly, to connect properly, I had to restart networking as #user1054844 mentioned as this:
/etc/init.d/networking restart
After all these steps, I was able to connect and work with the SQL Server database.
You actually did not need ODBC at all since your connect script is using pdo_dblib not odbc. You can just install FreeTDS than enable pdo_dblib via the compile time flag in rawopts and rebuild via EasyApache. Of course cPanel specifics for this are a bit different.
I just did this for a friend and decided to document it since it is hard to find accurate clear information for FreeTds and pdo_dblib on cPanel.
Guide is here: FreeTDS And pDO_dblib On cPanel

Categories