I'm trying to get rid of a document by _id, but the PHP process stops without error, and no error in access.log, and no output if i assign a variable to remove(). Using mongodb:
version v2.4.9
$connection = new MongoClient();
if($connection == NULL) {
return "some msg";
}
$db = $connection->main;
$collection = $db->users;
$document = $collection->findOne(array('email' => $user->email));
if($document == NULL) {
// do some stuff, works fine.
} else {
$id = $document["_id"];
echo "id=".$id // outputs: 5469a22600a8ebe8418b4567
if($document["confirm"] != "true") {
echo "confirmed not true" // outputs fine
$collection->remove(array('_id' => new MongoId($id)), true);
echo "hello!"; // never occurs
}
}
EDIT: I tried this, and no output:
try {
$collection->remove(array('_id' => new MongoId($id)), true);
} catch(Exception $e) {
echo $e->getMessage();
}
EDIT: I found an answer, but I don't understand the answer because every example I've seen includes the true argument. So I won't self answer this question and leave it up to an expert.
This doesn't work:
$collection->remove(array('_id' => new MongoId($id)), true);
This doesn't work:
$collection->remove(array('_id' => new MongoId($id)), false);
This works:
$collection->remove(array('_id' => new MongoId($id)));
I can explain your problem but I cannot explain why you are not seeing errors, there must be something odd in your PHP setup.
Anyway, as to why your boolean only value for the second parameter does not work: it is because the PHP driver expects an array: http://php.net/manual/en/mongocollection.remove.php the examples you worked from were either incredibly old (Since the change happened 1.0.5 http://php.net/manual/en/mongocollection.remove.php#refsect1-mongocollection.remove-changelog) or incorrect.
Related
I get this warning in a chunk of instructions PHP 8+ dedicated to the check of the user inside the page:
if ($_POST['go'] ?? null) {
// $_SESSION_VALUES is an array $db, $nick are classes of mine
$_SESSION_VALUES = $nick->get_cookie (COOKIE_NAME); // get the name of the cookie
if ($db->check_user (USERS_TABLE, $_POST['nick'], $db->encode_password($_POST['password']))) {
$_SESSION_VALUES['_USERNAME'] = $db->user_rec['nick']; // get the nickname from the cookie
$_SESSION_VALUES['_PASSWORD'] = $db->user_rec['password']; //get the password
$_SESSION_VALUES['_USER'] = $db->user_type;
if (! $nick->set_cookie (COOKIE_NAME, $_SESSION_VALUES)) die ('Cannot write the cookie'); // record the cookie
header('Location: ./copertina'); }
else $_SESSION_VALUES['_USER'] = -1;
}
The execution of
else $_SESSION_VALUES['_USER'] = -1;
gives "Automatic conversion of false to array is deprecated"
Following a suggestion from stack overflow I tryed this:
$\_SESSION_VALUES = \[\];
if ($\_POST\['go'\] ?? null) {
...
but apparently it doesn't work
any idea?
Thanks
I assume that $nick->get_cookie(COOKIE_NAME); returns false.
Try changing:
else $_SESSION_VALUES['_USER'] = -1;
to:
else $_SESSION_VALUES = ['_USER' => -1];
This will probably get rid of the error message you reported, but I don't know if the rest of your code, which I cannot see, will accept this.
I'm trying to export a CrystalReports report using PHP and save it to the server. I'm using PHP's COM class. I'm not able to get it to work, it just hangs on Export(true). My code is as follows:
$obj = new COM('CrystalReports13.ObjectFactory.1') or die('1');
$get = $obj->CreateObject('CrystalDesignRunTime.Application') or die('2');
$report = $get->OpenReport('C:\\xampp\htdocs\\crystal\\Packslip_RepSrv.rpt', 1) or die('3');
try {
$report->Database->ConvertDatabaseDriver('crdb_odbc.dll', false);
$report->Database->Tables(1)->SetLogOnInfo('REMOVED', 'REMOVED', 'REMOVED','REMOVED');
$report->EnableParameterPrompting = 0;
$report->DiscardSavedData;
$report->ParameterFields->Item(1)->AddCurrentValue('9455');
$report->ExportOptions->DiskFileName='report.pdf';
$report->ExportOptions->FormatType=31;
$report->ExportOptions->DestinationType=1;
$report->Export(false);
$report = null;
$get = null;
$obj = null;
print "<embed src=\"report.pdf\">";
} catch(Exception $e) {
var_dump($e);
}
Does anything above look out of the usual? To my knowledge I'm doing everything properly, but it hangs on the $report->Export(false); part.
Don't use CrystalDesignRunTime
Use CrystalRunTime
how to recognise i am able to log in to rets ?
This is my code and output.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//date_default_timezone_set('America/New_York');
require_once("vendor/autoload.php");
//$log = new \Monolog\Logger('PHRETS');
//$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
$config = new \PHRETS\Configuration;
$config->setLoginUrl('*****************');
$config->setUsername('****');
$config->setPassword('****');
$config->setUserAgent('****');
$config->setRetsVersion('1.7.2');
$config->setOption('disable_follow_location',false);
$config->setOption('use_post_method',true);
$rets = new \PHRETS\Session($config);
$rets->setLogger($log);
$connect = $rets->Login();
var_dump($connect->getBody());
output
Notice:
Trying to get property of non-object in
/var/www/html/glvar/rets/vendor/troydavisson/phrets/src/Parsers/GetMetadata/System.php
on line 26
Fatal error:
Call to a member function attributes() on a non-object in
/var/www/html/glvar/rets/vendor/troydavisson/phrets/src/Parsers/GetMetadata/System.php
on line 26
how can i know from this response that i am login in to rets and
i can get any data.
$config = new \PHRETS\Configuration;
$config ->setLoginUrl(***)
->setUsername(***)
->setPassword(***)
->setRetsVersion(***)
->setOption('use_post_method', false)
->setOption('disable_follow_location', false);
empty($user_agent') ? '' : $config->setUserAgent($user_agent);
empty($user_agent_password) ? '' : $config->setUserAgentPassword($user_agent_password);
$rets = new \PHRETS\Session($config);
$connect = $rets->Login();
if ($connect) {
echo " + Connected\n\n";
return $connect;
} else {
echo" + NotConnected\n\n";
}
Here is an ever better way to make sure.. add the code below you $connect and you should get something like the below.. and any response not an error should indicate a connection and show you what was returned..
$connect = $rets->Login();
print "<pre>";
print_r($connect);
print "</pre>";
This will be returned or some thing similar if you are connected..
PHRETS\Models\Bulletin Object
array {
[body:protected] =>
}
Watch out on the above answer.. I ran it on a live RETS feed and it stopped my program in its tracks.. and printed + Connected... I removed the return $connect and changed the \n to and it ran fine and printed Connected.. but my point is it may appear to work fine but the program will not go past the connection test... so it killed my program dead in its tracks... not sure why?
so I tried to get a fix for this earlier but I think we were all going in the wrong direction. I'm trying to check two servers to make sure that at least one of them are active to make a call to. The service provides me with a page for each that simply has "OK" under a div with id="server_status". When I try to loadHTMLFile into a variable, it returns true, but I can never pull the element I need from it. After doing some output testing with saveHTML(), it appears that the variable holding the DOMDocument is empty. Here's my code:
servers = array('tpeweb.paybox.com', // primary URL
'tpeweb1.paybox.com'); // backup URL
foreach($servers as $server){
$doc = new DOMDocument();
$doc->validateOnParse = true;
$doc->loadHTMLFile('https://'.$server.'/load.html');
$server_status = "";
$docText = $doc->saveHTML();
if($doc) {
echo "HTML should output here: ";
echo $docText;
}
if(!$doc) {
echo "HTML file not loaded";
}
$element = $doc->getElementById('server_status');
if($element){
$server_status = $element->textContent;
}
if($server_status == "OK"){
// Server is up and services are available
return array(true, 'https://'.$server.'/cgi/MYchoix_pagepaiement.cgi');
}
}
return array(false, 'e404.html');
All I get as output is "HTML should output here: " twice, and then it returns the array at the bottom. This is the code that they provided:
$servers = array('tpeweb.paybox.com', // primary URL
'tpeweb1.paybox.com'); // backup URL
$serverOK = "";
foreach($servers as $server){
$doc = new DOMDocument();
$doc->loadHTMLFile('https://'.$server.'/load.html');
$server_status = "";
$element = $doc->getElementById('server_status');
if($element){
$server_status = $element->textContent;
}
if($server_status == "OK"){
// Server is up and services are available
$serverOK = $server;
break;
}
// else : Server is up but services are not available .
}
if(!$serverOK){
die("Error : no server found");
}
echo 'Connecting to https://'.$server.'/cgi/MYchoix_pagepaiement.cgi';
This also seems to be having the same problem. Could it be something with my PHP configuration? I'm on version 5.3.6.
Thanks,
Adrian
EDIT:
I tried it by inputting the HTML as a string instead of calling it to the server and it worked fine. However, calling the HTML into a string to use in the PHP function results in the same issue. Fixes??
i try to handle exception and write code as follows but i also get exception when document save sucessfully in my databse.
$table = "MyRequestTable";
$smsID = new MongoId();
$data = array("_id" => $smsID,
"requestUserid" => 2500,
"requestDate" => new MongoDate(strtotime(date('Y-m-d H:i:s'))),
"requestNosSms" => 1
);
try
{
$result = $table->insert($data, array("safe" => TRUE));
echo $smsID ;
}
catch (Exception $e)
{
echo $e->getMessage();
}
i got following exception
"Invalid modifier specified: $push"
Even if INSERT command executed correct may be situation when some other instruction throws exception. Are you sure that other parts of code are correct?