I've got a little PHP script that has the following code in it:
$m = new MongoClient(Settings::$db);
$db = $m->db;
// get the 'customers' collection
$customers = $db->customers;
// determine if this customer already exists
$c = $customers.findOne(array('email' => $email)); <--- throws
if (is_null($c)) {
$customers.insert(array(
'email' => $email,
'firstname' => $firstName,
'lastname' => $lastName
));
}
// get the 'payments' collection
$payments = $db->payments;
// add a record
$payments->insert(array(
'email' => $email,
'firstname' => $firstName,
'lastname' => $lastName,
'amount' => $price,
'token' => $token
));
but it's throwing the error:
PHP Fatal error: Call to undefined function findOne() in ...
Now, I've downloaded and copied into the ext directory the php_mongo.dll file. Further, I've added this line to the php.ini:
extension=php_mongo.dll
and I've since rebooted the server numerous times.
It really feels to me like this findOne method isn't available because the php_mongo extension isn't loaded. But on the other hand, it's not throwing when creating the MongoClient, nor is it throwing when grabbing the database and the collection.
What's going on here?
As per my comment, you likely used another language's method access syntax by mistake:
This
$c = $customers.findOne(array('email' => $email));
is alas PHP so you need the object operator not the dot:
$c = $customers->findOne(array('email' => $email));
I think dot is the mistake.try
$c = $customers->findOne(array('email' => $email));
Related
I am completely new to PHP SOAP . After doing some R&D for my problem I got some links of stackoverflow but didn't get the perfect solution.
Here is my problem :
I am creating a SOAP client that will execute a method called GetPassword and It will return an encrypted password with response code '100' if the credentials is correct. In case of wrong credential a response code '101' and the response status will receive.
Here is my code (I am hiding the credentials for security purpose):
$url= "http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc?wsdl";
$method = "GetPassword";
$error=0;
$client = new SoapClient($url, array('soap_version' => SOAP_1_2 , 'SoapAction'=>'http://tempuri.org/IStarMFFileUploadService/GetPassword'));
$actionHeader= array();
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'Action',
'http://tempuri.org/IStarMFFileUploadService/GetPassword');
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'To',
'http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc/Basic');
$client->__setSoapHeaders($actionHeader);
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
try{
$info = $client->__call($method, array($param));
}
catch (SoapFault $fault) {
$error = 1;
}
if($error==1) {
$xml=$fault;
}else{
$xml = $info;
}
echo($xml);
Some couples of days ago I got this error and the error was happening due to the mismatch of parameters. But this time I think the parameters are correct. So may be I am doing some small mistakes.. Please help me to find the mistakes.
If any input needed, please let me know in the comment, I will update.
Please Note : I tested the wsdl URL with the SoapUI software and it is returning perfectly.
The Problem was with Parameter . Just analyze the structure of the Method GetPassword and found that it take only one parameter named 'Param' which is an object and inside the Param object it is taking the values of MemberId', 'Password' , 'UserId'.
So just need to change one line of code.
use
$param =array ('Param' => array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX') );
Instead of
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
and the issue resolved.
I'm using a third-party extension in Symfony to connect to SSRS: https://github.com/ChartBlocks/php-ssrs
I need to keep my SSRS datasource as "prompt for credentials" since we are also using another solution that requires that, but I'm unsure how to set the DataSourceCredentials in my solution. I get the error: System.Web.Services.Protocols.SoapException: One or more data source credentials required to run the report have not been specified.
Here's my code in my controller:
$options = [
'username' => $this->getParameter('ssrs_user'),
'password' => $this->getParameter('ssrs_password')
];
$ssrs = new SSRS\Report($this->getParameter('ssrs_server'), $options);
$result = $ssrs->loadReport($this->getParameter('ssrs_base').'/'.$request->get('report'));
$ssrs->setSessionId($result->executionInfo->ExecutionID);
$parameters = json_decode($request->get('parameters'),true);
$ssrs->setExecutionParameters(new SSRS\Object\ExecutionParameters($parameters));
$output = $ssrs->render('HTML4.0'); // PDF | XML | CSV | HTML4.0 | Excel
return $output;
Anyone know what I need to add to pass the DataSourceCredentials?
Found an answer by creating my own method in the Report.php file, until it's updated in the core:
public function setDataSourceCredentials($datasource,$username,$password) {
$this->checkSessionId();
$options = array(
'Credentials' => array(
'DataSourceCredentials' => array(
'DataSourceName' => $datasource,
'UserName' => $username,
'Password' => $password
)
)
);
$result = $this->getSoapExecution()->SetExecutionCredentials($options);
return new ExecutionInfo($result);
}
I call this in my controller before rendering the report:
$ssrs->setExecutionParameters(new SSRS\Object\ExecutionParameters($parameters));
$ssrs->setDataSourceCredentials($this->getParameter('ssrs_datasource'),$this->getParameter('ssrs_sql_user'),$this->getParameter('ssrs_sql_password'));
I am having trouble getting a response from an API using a http Client in Cake PHP 3
I want to send the following GET request but I cannot manage to return a result. If visit this url with a browser i get a response.
http://XX.XX.XX.XX:8020/mvapireq/?apientry=newuseru&authkey=XXXXXXXXXX&u_username=NEWUSERNAME&u_password=PASSWORD&u_name=NAME&u_email=EMAIL&u_phone=PHONE&u_currency=USD&u_country=USA&u_address=x&deviceid=DEVICEID&now=555
When I try to send the same request with http Client my reponse object is always null
use Cake\Network\Http\Client;
use Cake\Network\Http\Response;
public function foo(){
$http = new Client();
$data = [
'apientry' => 'newuseru',
'authkey' => 'XXXXXXXX',
'u_username' => 'NEWUSERNAME',
'u_password' => 'PASSWORD',
'u_name' => 'NAME',
'u_email' => 'EMAIL',
'u_phone' => 'PHONE',
'u_currency' => 'USD',
'u_country' => 'USA',
'u_address' => 'x',
'deviceid' => 'DEVICEID',
'now' => '555'
];
$response = $http->get('http://XX.XX.XX.XX:8020/mvapireq', $data);
debug($response->body);
debug($response->code);
debug($response->headers);
}
This is the results from the debug() it seems to me like the request is not being sent.
Notice (8): Trying to get property of non-object [APP/Controller/UsersController.php, line 1159]
/src/Controller/UsersController.php (line 1159)
null
Notice (8): Trying to get property of non-object [APP/Controller/UsersController.php, line 1160]
/src/Controller/UsersController.php (line 1160)
null
Notice (8): Trying to get property of non-object [APP/Controller/UsersController.php, line 1161]
/src/Controller/UsersController.php (line 1161)
null
/src/Controller/UsersController.php (line 1163)
null
I've tried many different ways of structuring $http and all of them have returned the same result. I really can't figure out whats going wrong. Any help would be great.
You can specify hostname and port in the constructor of the Client:
<?php
use Cake\Network\Http\Client;
// ....
public function foo(){
$http = new Client([
'hostname' => 'XX.XX.XX.XX',
'port' => '8020'
]);
$data = [
'apientry' => 'newuseru',
//....
'now' => '555'
];
$response = $http->get('/mvapireq', $data);
// ...
}
And check your system:
firewall (os)
allow_url_fopen (in your php runtime configuration)
Okay, had no luck with the ZETA email client, so now I tried installing the Horde IMAP Client library. I've managed to login to my account, and make a search for e-mails, also got back the results, but I don't know how to fetch the email data, and the documentation is not really helping:|
I presume that I would have to use the Horde_Imap_Client_Base::fetch() method to get some e-mails, which accepts two parameters, a mailbox name, and a Horde_Imap_Client_Fetch_Query object, but I don't know how to get this second object:|
Should this object be returned by one of the Base functions, or should I build this object with the query parameters I want? If the second, how should I rebuild my search query in the fetch query object from the below example?
Here's how I am searching my INBOX, for mails from a specific contact on a specific day:
$client = new Horde_Imap_Client_Socket(array(
'username' => 'my.email#address.com',
'password' => 'xxxxxxxxxx',
'hostspec' => 'my.mail.server',
'port' => '143',
'debug' => '/tmp/foo',
));
$query = new Horde_Imap_Client_Fetch_Query();
$query->dateSearch(new Date(), Horde_Imap_Client_Search_Query::DATE_ON);
$query->headerText("from","mycontact#contact.email");
$results = $client->search('INBOX', $query);
The Horde_Imap_Client_Base::search() returns an array, which contains the search results(the message id's of the searched emails), and some additional data.
Not completely answering your questions. This is how I search for messages which are not deleted.
$client = new Horde_Imap_Client_Socket(array(
'username' => $user,
'password' => $pass,
'hostspec' => $server,
'secure' => 'ssl'
));
$query = new Horde_Imap_Client_Search_Query();
$query->flag(Horde_Imap_Client::FLAG_DELETED, false);
$results = $client->search('INBOX', $query);
foreach($results['match'] as $match) {
$muid = new Horde_Imap_Client_Ids($match);
$fetchQuery = new Horde_Imap_Client_Fetch_Query();
$fetchQuery->imapDate();
$list = $client->fetch('INBOX', $fetchQuery, array(
'ids' => $muid
));
var_dump($list);
}
$results = $client->search($mailbox, $searchquery, array('sort' => array($sSortDir, $sSort)));
$uids = $results['match'];
for ($i = $i_start; $i < $i_to; $i++)
{
$muid = new Horde_Imap_Client_Ids($uids->ids[$i]);
$list = $client->fetch($mailbox, $query, array(
'ids' => $muid
));
$flags = $list->first()->getFlags();
$part = $list->first()->getStructure();
$map = $part->ContentTypeMap();
$envelope = $list->first()->getEnvelope();
}
I am using the following php script in mule. When i am running this php file individually(through wamp) i am able to get the required output.
<?php
$client1=new SoapClient('example/v2_soap?wsdl', array('trace' => 1, 'connection_timeout' => 120));
$username = '******';
$password = '******';
//retreive session id from login
$session = $client1->login(
array(
'username' => $username,
'apiKey' => $password,
)
);
$result= $client1->catalogProductInfo(
array(
'sessionId' => $session->result,
'productId' => 1,
)
);
print_r($result);
return $result;
?>
But i want to run the following script through mule. So when i am running it through mule i am getting the following error.
Root Exception stack trace:
com.caucho.quercus.QuercusErrorException: eval::5: Fatal Error: 'SoapClient' is an unknown class name.
at com.caucho.quercus.env.Env.error(Env.java:4480)
at com.caucho.quercus.env.Env.error(Env.java:4399)
at com.caucho.quercus.env.Env.createErrorException(Env.java:4130)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
It says SoapClient is an unknown class. What is the problem here?
Do i have to include some SoapClient here? If so where can i find it. Please help!!
I'm not sure if mule supports php extensions, but that's what it seems by the error. You could try downloading nusoap into your project,
which doesn't require any php extension. The syntaxis is a little bit different though, but shouldn't be harder to adapt your code.
For what it's worth, this is a simple example of a soap request using nusoap (taken from here http://www.richardkmiller.com/files/msnsearch_nusoap.html):
require_once('nusoap/lib/nusoap.php');
$request = array('Request' => array(
'AppID' => 'MSN_SEARCH_API_KEY',
'Query' => 'Seinfeld',
'CultureInfo' => 'en-US',
'SafeSearch' => 'Strict',
'Flags' => '',
'Location' => '',
'Requests' => array(
'SourceRequest' => array(
'Source' => 'Web',
'Offset' => 0,
'Count' => 50,
'ResultFields' => 'All'))));
$soapClient = new soapclient("http://soap.search.msn.com/webservices.asmx?wsdl", false);
$result = $soapClient->call("Search", $request);
print_r($result);
I hope it helps.
I understand there seems to be a problem with running the soap client inside quercus (rather than Mule).
However instead of focusing on it I would suggest to take a look to the CXF client and the Web services consumer. You are running inside of Mule a powerful opensource ESB, there is no need to write a php script to consume a service, you have all that functinality already present.