I'm having a problem with connecting to MongoDB with PHP.
This is my code:
<?php
$server = new Mongo('localhost:27017');
$db = $server->sampleDB;
$coll = $db->sample;
?>
This produces the following error:
Fatal error: Uncaught exception 'MongoConnectionException' with message 'localhost:27017: couldn't get host info for localhost' in /var/www/example/index.php:2 Stack trace: #0 /var/www/example/index.php(2): Mongo->__construct('localhost:27017') #1 {main} thrown in /var/www/wexample/index.php on line 2
Found the problem;
Turns out for some reason Mongo was only listening on 127.0.0.1, not localhost.
So, using $server = new Mongo("mongodb://127.0.0.1:27017");, instead of $server = new Mongo("mongodb://localhost:27017"); fixed the problem :)
Thanks for your help guys,
James
Following the PHP Manual
couldn't get host info for [server]
This indicated that DNS could not
resolve the server address you gave.
This could easily be caused by a typo,
for example, "server" instead of
"$server".
As well, you might want to read the Connecting part of the MongoDB section in PHP doc
EDIT
Have you tried this ?:
$server = new Mongo("mongodb://localhost:27017");
Related
I have a problem when I try to log to my database with php. I have a website in php and I need to use a database so I have file where I try to connect :
$db = new PDO('mysql:host=IP;dbname=DB_Name', 'Username', '********');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
Then I have an error :
Fatal error: Uncaught PDOException: Packets out of order. Expected 0
received 1. Packet size=78 in /var/www/html/index.php:6 Stack trace:
#0 /var/www/html/index.php(6): PDO->__construct() #1 {main} Next PDOException: SQLSTATE[HY000] [2006] MySQL server has gone away in
/var/www/html/index.php:6 Stack trace: #0 /var/www/html/index.php(6):
PDO->__construct() #1 {main} thrown in /var/www/html/index.php on line
6
My database is on a VPS. The database is installed on it with my php code.
I already looked on internet for solution but nothing changed.
Thanks for your help.
if you’re getting the Packets out of order error in the PHP log, there’s an high chance that the issue is due to the fact that there’s an incompatibility between the PHP and MySQL versions you’re using. If upgrading them is not an option, you could try to add the following statement to the PHP script that causes the issue:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
Maybe this may help...
screenshot of "SHOW VARIABLES LIKE '%timeout%'"
We used "cPanel API2" library to create park domain in our server and it was working fine until last cPanel up-gradation.
We created file mytest.live.php on server to create a object of "CPANEL class" for troubleshooting the issue, but unfortunately it returns error as below.
<?php
require_once "/usr/local/cpanel/php/cpanel.php";
$cpanel = new CPANEL(); ?>
And Output Returns:
Fatal error: Uncaught exception 'RuntimeException' with message 'There was a problem fetching the env variablecontaining the path to the socket' in /usr/local/cpanel/php/cpanel.php:146 Stack trace: #0 /home/cityusa/public_html/mytest.live.php(4): CPANEL->__construct() #1 {main} thrown in /usr/local/cpanel/php/cpanel.php on line 146
So please help for resolve this issue.
You should try naming your file as ".live.php" or ".livephp". That worked for me.
I've got Cassandra working nicely on Debian server however I'm hoping to connect to it from a PHP application.
Currently it seems PDO it the way to go for anything complex as I'm able to use CQL. I'm using the latest forked version of the Apache Cassandra-PDO project.
I'm using the latest Cassandra 2.03 and I can connect to it fine from CQLSH in the terminal.
When I try and connect in PHP using the following code
$db_handle = new PDO("cassandra:host=localhost;port=9160");
I get the following error
Fatal error: Uncaught exception 'PDOException' with message 'CQLSTATE[08006] [8] TTransportException: Transport not open' in /var/www/index.php:9 Stack trace: #0 /var/www/index.php(9): PDO->__construct('cassandra:host=...') #1 {main} thrown in /var/www/index.php on line 9
I've seem a few issues alike on the internet, but no solutions as yet. Hopefully someone can provide some insight into the issue here.
Error 8006 is connection failure. I think you need login and password in PDO Statment like this:
$pdo = new PDO('mysql:host=localhost;dbname=products', 'root', 'root');
Try running 'nodetool status' from the cli to verify the IP address the server is running on.
Then perhaps change localhost to 127.0.0.1 if instead the local host.
I have a cloud server with CentOS 6, Apache 2.2, PHP 5.4 and i have one site with Magento.
And i try to use a Magento WebService and return this error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://******.com/dev/index.php/api/soap/index/?wsdl=1' : failed to load external entity "http://******.com/dev/index.php/api/soap/index/?wsdl=1"
I search here and in google, and i try many changes in php.ini, but in all cases i don't have success.
I read in some cases this is a problem in server side, for bad configuration.
Note¹: SOAP is installed in server, in phpinfo() SOAP is enabled.
Note²: On another server was working normally.
Anyone have any ideia how to solve this?
Edit: The server use WHM/CPanel and i use EasyApache for install Apache, PHP. And use default configuration.
Edit2: This is just a simple sample code that uses the SOAP and error it returns:
Code: (first line of this code is a line 9, and line 13 is "$cli = new SoapClient($api_url_v1);")
<?php
$api_url_v1 = "http://site.com/dev/api/soap/?wsdl=1";
$username = '*********';
$password = '*********';
$cli = new SoapClient($api_url_v1);
//retreive session id from login
$session_id = $cli->login($username, $password);
//call customer.list method
$result = $cli->call($session_id, 'customer.list', array(array()));
?>
Error:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://site.com/dev/api/soap/?wsdl=1' : failed to load external entity "http://site.com/dev/api/soap/?wsdl=1" in /home/******/public_html/test_soap.php:13 Stack trace: #0 /home/******/public_html/test_soap.php(13): SoapClient->SoapClient('http://site...') #1 {main} thrown in /home/******/public_html/test_soap.php on line 13
try to fetch the wsdl via webbrowser. if this does not work then you have an error in url. try www version of the urls, check for bad rewrites, check htaccess. you dont need https!
Mongo DB showing an error Fatal error: Uncaught exception 'MongoConnectionException' with message 'Operation now in progress' in PHP. How to resolve this error and why this error comes.
This typically means the driver has issues connecting to the database. I've learned this through the very first result in Google when pasting your question ;)
As Remon said, "I have an error please help" doesn't work very well when asking programming questions.
Usual things to make sure are, that Mongodb is running and you are connecting to the right host:port e.g.
$m = new Mongo();
If it's not in the localhost (your machine) and default port try this.
$con = new Mongo("mongodb://{$username}:{$password}#{$host}");
Also try to connect to the database using the mongo shell interface.
I had this issue when trying to connect to ObjectRocket. The solution was to add my IP to the ACLs and then I no longer got this error.