I am getting this error in Apache2 errors logs:
PHP Fatal error: Function 'ns1:getClients' doesn't exist
I checked to see why the PHP Soap Server is not locating the method in the class Client_API and can't see any course here's the index.php file:
require(INCLUDES_DIR.'BaseService.class.php');
require($interfaceFile);
require($serviceFile); // loads /var/www/official-productionapi/includes/Client.service.php
//...
$server = new SoapServer(null, array ('uri'=>'', 'trace' => 1, 'connection_timeout' => intval(600)));
$server->setClass($serviceName.CLASS_SUFFIX); // -- e.g. 'Client_API'
$server->handle();
The Class containing the missing method:
class Client_API extends BaseService implements Client_API_Interface
{
public function getClients($range = 10, $search, $accessUserID = null)
{
if(!$this->Authenticated){
throw new SoapFault('Server', 'Authorization failed: Wrong username or password');
}
$max = 100;
$range = (int)$range;
if($range > $max){
$range = $max;
}
$clients = array();
$db = Database::getInstance();
if(null !== $accessUserID){
$sql = "SELECT * FROM clients as c, users_clients_access as uac WHERE c.ClientID = uac.ClientID AND uac.UserID = '".$db->escape($accessUserID)."' AND c.IsShopAssistClient = 0 AND (c.ClientName LIKE '".$db->escape($search)."%' OR c.Tag LIKE '".$db->escape($search)."%') ORDER BY c.ClientName Asc LIMIT $range";
}else{
$sql = "SELECT * FROM clients WHERE IsShopAssistClient = 0 AND (ClientName LIKE '".$db->escape($search)."%' OR Tag LIKE '".$db->escape($search)."%') ORDER BY ClientName Asc LIMIT $range";
}
$clientQ = $db->query($sql);
while($client = $db->fetch_array($clientQ)){
$arr = array();
$arr['PClientName'] = $client['ClientName'];
$arr['PClientTag'] = $client['Tag'];
$clients[$client['ClientID']] = $arr;
}
return $clients;
}
//...
Any help would be appreciated, I have been thinking if it has something to do with PHP version mismatch, it was working on version 5.3.3 but it's not on version 5.3.10. So only minor differences.
I have been able to solve this issue by setting uri option to 'uri'=>'api'. Seems like leaving it blank wasn't a good idea. It still boggles me how it works on the same version of PHP on Windows just fine.
This post led me to my answwer: Issues with SOAP in non-WSDL mode.
Related
I use the Vtiger webservice with its different methods CRUD, login ... etc. I created a task via the Calendar module, it worked well, but when I want to delete it does not work.
If I'm not mistaken, I need to have the object's id (so Calendar) in order to delete it. So I do:
public static function getTaskUser($user)
{
$idUser = self::getUserAccountId('XXXX');
$vtiger = new VtigerWS();
$connect = $vtiger->getConnection();
if ($connect && $connect['success'] == true) {
$response = $vtiger->query("id", "Calendar", "parent_id = '$idUser' ORDER BY id");
if ($response['success'] == false) {
$result = $response['error'];
} else {
$result = array();
foreach ($response['result'] as $task) {
$result[] = $task['id'];
}
}
} else {
$result = $connect['error'];
}
$vtiger->logout();
return $result;
}
==> In this function, I first look for the user id in vtiger (the user who was assigned to the previously created task). It works well.
But when the query is running:
($ vtiger-> query ("id", "Calendar", "parent_id = '$ idBaz' ORDER BY id");)
I get an error:
"code" => "DATABASE_QUERY_ERROR"
"message" => "Database error while performing requested operation"
The connection is good, I tried a query SELECT * FROM Calendar it does not work either ... I do not see where the error can come from.
So, I've developed the following code:
const MAILGUN_API_MAX_LIMIT = 300; //max in documentation
$mgClient = new Mailgun\Mailgun("<mailgun_key>");
$domain = "<my_domain>";
$resultItems = array();
try {
$result = null;
$endTime_Epoch = time();
$startTime_Epoch = $endTime_Epoch - 1440000; //400 hours
$queryParams = array(
'begin' => $endTime_Epoch,
'end' => $startTime_Epoch,
'limit' => MAILGUN_API_MAX_LIMIT,
'ascending' => 'no',
'event' => 'rejected OR failed',
);
$request_url = "$domain/events";
do {
$result = $mgClient->get($request_url, $queryParams);
if(!$result->http_response_body) {
/*...*/
} else if($result->http_response_code != 200) {
/*...*/
} else {
$resultItems[] = $result->http_response_body->items;
if(count($result->http_response_body->items) == MAILGUN_API_MAX_LIMIT) {
$request_url = $result->http_repsonse_body->paging->next;
}
}
} while($result && $result->http_response_body && count($result->http_response_body->items) == MAILGUN_API_MAX_LIMIT);
} catch (Exception $e) {
echo $e->getMessage()
}
But I'm having trouble getting it to page through the next set of requests if the limit ever gets hit (it probably won't, but it'd be bad in the event that something happened that made it happen).
I've tried reading mailgun's api doc, but i cannot, for the life of me, figure out what it is talking about with this:
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$nextPage = 'W3siYSI6IGZhbHNlLC';
# Make the call to the client.
$result = $mgClient->get("$domain/events/$nextPage");
But i can't figure out what that $nextPage is supposed to be. I've tried peeling off the start of the paging->next so it just ends up being $domain/events/, but that doesn't seem to be paging though it. I'm not really sure what to do here, or even what I'm supposed to do.
I know this is a bit later than you would've hoped, but I've also been doing some stuff with the Mailgun and PHP lately.
So $nextPage is a value provided after your first API requests, so you don't need it at the start. Simply make your normal request like so
$result = $mailgun->get("$domain/events", $queryString);
// then we can get our 'Next Page' uri provided by the request
$nextURI = $result->http_response_body->paging->next;
// now we can use this to grab our next page of results
$secondPageResults = $mailgun->get($nextURI, $queryString);
Once thing worth noting though, is that Mailgun seems to always provide a 'next' link even when you've got all the results you want.
In my project I collected all results using a while loop after getting my initial records:
$hasNext = count($items) >= $queryLimit;
while($hasNext) {
$nextResult = $mailgun->get($lastResult->http_response_body->paging->next, $queryString);
$nextItems = $nextResult->http_response_body->items;
$items = array_merge($items, $nextItems);
$hasNext = count($nextItems) >= $queryLimit;
$lastResult = $nextResult;
}
Hope this helps!
My hosting provider has PHP 5.3 without mysqlnd installed, and thus it returns an error when I call mysqli_stmt_get_result()
is there any workaround to achieve the same functionality without having to install mysqlnd?
I don't want to change 100's of functions, if there's an easier method, any help will be appreciated :)
I went through a lot of trouble on a server where mysqlnd wasn't available, and had a lot of headaches.
If you don't have mysqlnd installed/loaded whatever, you will get an undefined reference when trying to call mysqli_stmt_get_result().
I wrote my own mysqli_stmt_get_result() and a mysqli_result_fetch_array() to go with it.
<?php
class iimysqli_result
{
public $stmt, $nCols;
}
function iimysqli_stmt_get_result($stmt)
{
/** EXPLANATION:
* We are creating a fake "result" structure to enable us to have
* source-level equivalent syntax to a query executed via
* mysqli_query().
*
* $stmt = mysqli_prepare($conn, "");
* mysqli_bind_param($stmt, "types", ...);
*
* $param1 = 0;
* $param2 = 'foo';
* $param3 = 'bar';
* mysqli_execute($stmt);
* $result _mysqli_stmt_get_result($stmt);
* [ $arr = _mysqli_result_fetch_array($result);
* || $assoc = _mysqli_result_fetch_assoc($result); ]
* mysqli_stmt_close($stmt);
* mysqli_close($conn);
*
* At the source level, there is no difference between this and mysqlnd.
**/
$metadata = mysqli_stmt_result_metadata($stmt);
$ret = new iimysqli_result;
if (!$ret) return NULL;
$ret->nCols = mysqli_num_fields($metadata);
$ret->stmt = $stmt;
mysqli_free_result($metadata);
return $ret;
}
function iimysqli_result_fetch_array(&$result)
{
$ret = array();
$code = "return mysqli_stmt_bind_result(\$result->stmt ";
for ($i=0; $i<$result->nCols; $i++)
{
$ret[$i] = NULL;
$code .= ", \$ret['" .$i ."']";
};
$code .= ");";
if (!eval($code)) { return NULL; };
// This should advance the "$stmt" cursor.
if (!mysqli_stmt_fetch($result->stmt)) { return NULL; };
// Return the array we built.
return $ret;
}
?>
This related question has another workaround to get data without installing mysqlnd. It puts the data into an associative array.
Mysqli - Bind results to an Array
The solution from Daan is very nice! For this, i have to say thank you!
The point is, that i had, based on this, developed a class which works with mysqlnd, when it's there and Daan's alternative when it's missing.
I have built in fetchAssoc, fetchAllAssoc/Array, num_rows as methods. It's still in development and part of youphptube. This maybe also helps Ehab (whish for fetchAssoc).
https://github.com/DanielnetoDotCom/YouPHPTube/blob/master/objects/mysql_dal.php
Usage:
$sql = "SELECT * FROM users WHERE id = ?";
$res = sqlDAL::readSql($sql,"i",array($users_id));
$fullData = sqlDAL::fetchAllAssoc($res);
// $data = sqlDAL::fetchAssoc($res); $data2 = sqlDAL::fetchAssoc($res); // or like this
// $countedRows = sqlDAL::num_rows($res); // or like this
sqlDAL::close($res);
I would made this as a sub-post to Daan's answer, but my reputation is too small.
I use FOSElasticaBundle in my project to search a list of ads. I can get all the result but I can't order it in "asc" or "desc". I have seen different tutorial speaking about Filtering. But it's not working.
if (!empty($cati)) {
$query = new \Elastica\Query\Bool();
if((!empty($cati)) && $cati!='1')
{
$query1 = new \Elastica\Query\Match();
$query1->setFieldQuery('post.cat_id', $cati);
$query->addMust($query1);
}
}
else {
$query = new \Elastica\Query\MatchAll();
}
$elasticaQuery = new \Elastica\Query();
$elasticaQuery->setQuery($query);
$elasticaQuery->setSize($nbPerPage);
$elasticaQuery->setFrom(($page - 1) * $nbPerPage);
$elasticaQuery->addSort(array('date', array("desc"));
$repistoryManager = $this->container->get('fos_elastica.manager');
$repistory = $repistoryManager->getRepository('AdsManagerBundle:Post');
$eq = new \Elastica\Query();
$eq->setQuery($query);
$finder = $this->container->get('fos_elastica.index.ads.post');
$elasticaResultSet = $finder->search($eq);
$ed = $elasticaResultSet->getResults();
I can't get where the problem is!
You did in a mistake in your code (parse error + bad construction of the JSON syntax):
$elasticaQuery->addSort(array('date' => 'desc'));
I have two databases I need to connect to, which I can do in the controllers and libraries I have written. For some odd reason (i'm assuming I'm just missing something simple here) I can't get it to work in the model all of the sudden. I have read the database class in the CI user guide.
I tried making a reference to $pew when loading pew ($this->pew =& $this->load->database('pew', TRUE)) to no avail.
Any thoughts, suggestions? Thanks!
Error
PHP Fatal error: Call to a member function query() on a non-object in
/Sites/CI/nyan/application/models/pewpewmodel.php on line 15
Line 15
$this->pew->query('SELECT * FROM ExtractEvent'); //simplified for testing
database.php:
$active_group = 'nyan';
$active_record = TRUE;
$db['nyan']['hostname'] = 'catcatcat';
$db['nyan']['username'] = 'mew';
$db['nyan']['password'] = 'meow';
$db['nyan']['database'] = 'meow';
$db['nyan']['dbdriver'] = 'mysql';
$db['pew']['hostname'] = 'jujubees';
$db['pew']['username'] = 'qwop';
$db['pew']['password'] = 'qwop';
$db['pew']['database'] = 'nom';
$db['pew']['dbdriver'] = 'mssql';
Model pewpewmodel.php
private $pew;
function __construct()
{
parent::__construct();
$this->pew = $this->load->database('pew', TRUE);
}
function get_forms_by_date($id = NULL, $Year = NULL, $Month = NULL, $Day = NULL)
{
$this->pew->query('SELECT * FROM ExtractEvent'); //simplified for testing
}
Controller nomnom.php
public function index()
{
$this->load->model('pewmodel');
$data['Forms'] = $this->pewmodel->get_forms_by_date($this->session->userdata('Username'), date('Y'), date('n'), date('j'));
$this->load->view('common/header', $data['Forms']);
$this->load->view('home/index');
$this->load->view('common/footer');
}
View index.php
<pre>
<?php print_r($Forms); ?>
</pre>
This worked for me.
[from within the model constructor]
$db['hostname'] = 'localhost';
$db['username'] = 'root';
$db['password'] = '';
$db['database'] = 'my_database';
$db['dbdriver'] = 'mysql';
$db['dbprefix'] = '';
$db['pconnect'] = TRUE;
$db['db_debug'] = TRUE;
$db['cache_on'] = FALSE;
$db['cachedir'] = '';
$db['char_set'] = 'latin1';
$db['dbcollat'] = 'latin1_bin';
$db['swap_pre'] = '';
$db['autoinit'] = TRUE;
$db['stricton'] = FALSE;
$this->load->database($db, FALSE, TRUE);
// False=don't return db object
// True =use as active record, so it replaces default $this->db
Hope this helps coders searching through Google like I did.
$this->pew = $this->load->database('pew', TRUE);
You load a database which doesn't exist in your database-configuration.
I was getting a 500 error when I passed TRUE to connect like below. I assumed (yeah I know) that I was just having the same problem with connecting. truth be told it was an ID10T error from the beginning. I was missing the mssql.so library on my local machine and another I was testing from.
$this->pew =& $this->load->database('pew', TRUE)
My apologies for the waste of time gents.