I have gone through lots of post from StackOverflow and other sites. Following is the solution which I found almost on all sites But its not working for me. :-
return new \Phalcon\Db\Adapter\Pdo\MySql(array(
"host" => 'XXXx',
"username" => 'XXXX',
"password" => 'XXXX',
"dbname" => 'XXXX',
"options" => array(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true)
));
My code for calling Store Procedures:
public function AssignPromoterToPromotionVenuAction($bookingSheetID = 0, $promoter_id = 0, $userID = 0)
{
$query = "CALL `x_wf_AgencyAssignPromoter`($bookingSheetID, $promoter_id, $userID)";
$rp = new Promotion();
return new Resultset(null, $rp, $rp->getReadConnection()->query($query));
}
public function RemovePromoterToPromotionVenuAction($bookingSheetID = 0, $promoter_id = 0, $userID = 0)
{
$query = "CALL `x_wf_AgencyRemovePromoter`($bookingSheetID, $promoter_id, $userID)";
$rp = new Promotion();
return new Resultset(null, $rp, $rp->getReadConnection()->query($query));
}
Finally got the solution :
instead of returning a Resultset you can fetch the result of calling the procedure:
return $rp->getReadConnection()->query($query)->fetchAll();
Ref Link
Related
I am using Square Charge API, and following is my request object for a test card -
I am using Square provided PHP client to connect to the API. And I am receiving following response for "Charge" endpoint -
[HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"BAD_REQUEST","detail":"invalid character 'C' looking for beginning of value (line 1, character 1)"}]}
Following is my code in PHP -
public function chargeCustomerCard($userId, $custId, $cardId, $note, $billingAddres, $amount, $idempotencyKey){
$billingAddrRequest = array("address_line_1" => $billingAddres->addr1, "address_line_2" => $billingAddres->addr2, "locality" => $billingAddres->city, "administrative_district_level_1" => $billingAddres->state, "postal_code" => $billingAddres->zip, "country" => $billingAddres->country);
$billingAddressReq = new \SquareConnect\Model\Address($billingAddrRequest);
$moneyRequest = array("amount" => $amount, "currency" => "USD");
$money = new \SquareConnect\Model\Money($moneyRequest);
$request = array("idempotency_key" => $idempotencyKey, "customer_id" => $custId, "customer_card_id" => $cardId, "delay_capture" => false, "amount_money" => $money, "billing_address" => $billingAddressReq, "note" => $note, "reference_id" => $userId);
$charge = new \SquareConnect\Model\ChargeRequest($request);
$response = null;
try{
$charge_api = new \SquareConnect\Api\TransactionsApi();
$response = $charge_api->charge($this->authtoken, $this->locationId, $charge);
if($response != null && count($response->getErrors()) == 0){
$transaction = $response->getTransaction();
$data = array();
$data['transactionId'] = $transaction->getId();
$data['created'] = $transaction->getCreatedAt();
$data['referenceId'] = $transaction->getReferenceId(); //this should be equal to userid
$tender = $transaction->getTenders()[0];
$data['tenderId'] = $tender->getId();
$data['note'] = $tender->getNote();
$data['amount'] = ($tender->getAmountMoney()->getAmount())/100;
$data['currency'] = $tender->getAmountMoney()->getCurrency();
$processingFee = $tender->getProcessingFeeMoney();
if(isset($processingFee) && !empty($processingFee)){
$data['processingFee'] = $tender->getProcessingFeeMoney()->getAmount();
}else{
$data['processingFee'] = 0;
}
$data['tendertype'] = $tender->getType();
$data['cardStatus'] = $tender->getCardDetails()->getStatus();
$data['cardBrand'] = $tender->getCardDetails()->getCard()->getCardBrand();
$data['cardLast4'] = $tender->getCardDetails()->getCard()->getLast4();
$data['idempotencyKey'] = $idempotencyKey;
$data['customerPayId'] = $custId;
$data['customerCardId'] = $cardId;
return $this->generateReturnData(PAY_API_SUCCESS, '', $data);
}else{
return $this->generateReturnData(PAY_API_FAIL, '', $response->getErrors());
}
}catch(Exception $e) {
return $e->getMessage();
}
}
Can someone please point out to me what am I doing wrong here. I am really stuck here. Other API endpoints are working fine, such as, Create Customer, Create Customer Card API endpoints, using the same approach and same PHP client provided by square.
PS - this is on sandbox
How can i display all the otrs tickets using a soap api. Individual ticket can be displayed by passing ticket id in url like this:
$url = "https://url/otrs/rpc.pl"; //// URL for OTRS server
$username = "username"; //// SOAP username set in sysconfig
$password = "password"; //// SOAP password set in sysconfig
$TicketID = $_GET['id'];
//////// Initialize new client session ////////
$client = new SoapClient(
null,
array(
'location' => $url,
'uri' => "Core",
'trace' => 1,
'login' => $username,
'password' => $password,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED
)
);
//////// Create and send the SOAP Function Call ////////
$sql =
$TicketDetails = $client->__soapCall("Dispatch",
array($username, $password,
"TicketObject", "TicketGet",
"TicketID", $TicketID,
));
$ticketInfo = array();
$i = 0;
foreach ($TicketDetails as $name => $value){ //// explode the xml response
if (false !== strpos($name, "s-gensym")){
$temp[$i] = $value;
$v = $temp[$i - 1];
if($i % 2 != 0){
$ticketInfo[$v] = $value;
}
$i++;
}
}
var_dump($ticketInfo);
exit();
How can i display all the tickets using api?????
Use the TicketSearch API call in order to retrieve a list of Ticket IDs. Then feed this list to TicketGet as you already showed in order to retrieve ticket details.
I'm struggling with implementing PHP and MySQL Transactions. The script receives a SQL-statement along with some bindparameters through a blocking redisqueue. Everything is passed to a function 'do_transaction' which keeps track of the number of statements received.
I've debugged the PDO statement (after it has been processed) with PdoDebugger and the output is correct:
UPDATE bla SET processed = 1, severity_ou1 = 'low',
severity_ou2 = 'low', severity_ou3 = 'low', severity_ou4 = 'low',
severity_ou5 = 'low', saved = '1', hname = '1', sname = '1', if = '1',
v = '1', translated = 'blablabla.', filtered = 1, repeated = '1',
excessed = '1', eventfilterid = '212', building = '1', floor = '1'
WHERE id = '121614624'
global $batchcount;
$batchcount = 1;
while(true){
$redis = new Redis();
$redis->connect('xxx', xxx);
$sqlbatch = $redis->blpop('xxx:xxx:sqlfiltermatch', 0);
// blpop returns array: 0 has key, 1 has data.
if(is_array($sqlbatch)){
if(isJson($sqlbatch[1])){
$batchstatements = array();
$batchstatements[] = json_decode($sqlbatch[1], true);
// Get statement and bindparams.
$sqlstatement = $batchstatements[0]['statement'];
$bindparams = $batchstatements[0]['bindparams'];
// Replace empty bindparams.
foreach($bindparams as $column => $value){
if(is_null($value)){ $bindparams[$column] = '1'; }
if(empty($value)){ $bindparams[$column] = '1'; }
}
}
$batchcount++;
do_transaction($sqlstatement, $bindparams, $batchcount);
}
}
function do_transaction($sqlstatement, $bindparams){
global $batchcount;
if($batchcount >= 4){
try {
// Setup DB
$db = new PDO('mysql:host=xxx;dbname=xxx;charset=utf8', 'xxx', 'xxx', array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_AUTOCOMMIT => FALSE, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
echo $db->getAttribute(PDO::ATTR_AUTOCOMMIT)."\n\n";
$db->beginTransaction();
$stmt = $db->prepare($sqlstatement);
// Setup bindparams.
foreach($bindparams as $column => $value){
$stmt->bindParam(":$column", $value);
}
$stmt->execute() or die(print_r($stmt->errorInfo(), true));
echo PdoDebugger::show($sqlstatement, $bindparams)."\n";
$db->commit();
} catch(PDOExecption $e){
//$db->rollback();
print_r("ERROR"); exit;
}
$batchcount = 0;
}
$batchcount++;
}
I've made sure that AUTOCOMMIT = FALSE. Where in "do_transaction" does it go wrong?
There is no point in using transactions this way.
So, just leave them alone.
function do_query($db, $sqlstatement, $bindparams){
$stmt = $db->prepare($sqlstatement);
$stmt->execute($bindparams);
return $stmt;
}
is all the code you actually need.
Use it this way
$db = new PDO('mysql:host=xxx;dbname=xxx;charset=utf8', 'xxx', 'xxx',
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);
while(true){
// whatever redis code goes here
do_query($db, $sqlstatement, $bindparams);
}
Nota bene: If you want to make your inserts faster, you should ask a question titled "How to make inserts faster", no "My transactions do not work".
But your idea of inserting transactions is wrong too.
A single transaction (in terms of the business logic) have to be written to database as soon as possible, without interfering with other transactions. Means you should never couple different business logic transactions within single database transacion. Because error in single business logic transaction will ruin whole batch. So - just write them separately.
I couldn't find any proper example how to execute multiple insert query in codeigniter. I already tried make a function in models, containing more than 1 insert query. What I get always first query success, and others not executed at all.
I've already try use transaction: $this->db->trans_start();
In my case below: $db->trans_start(); and off course $db->trans_complete();
But that didn't help. Always only first insert query that executed. What should I do to execute all insert/update/delete queries in one fuction?
Example:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Deposit_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
public function inputdeh()
{
$this->load->helper('url');
$CI =& get_instance();
$db = $CI->load->database( 'local', TRUE );
$id_member = $this->input->post('id_member');
$jumlah = $this->input->post('jumlah');
$ket1 = $this->input->post('ket');
$ket = 'WEB/'.$ket1;
$saldoawal = $db->query("select saldo from member where id_member='$id_member'");
$saldoawa['saldo'] = $saldoawal->row('saldo');
$saldoaw = $saldoawa['saldo'];
$saldoak = $saldoaw + $jumlah;
//$_POST[jumlah]=number_format($_POST['jumlah'],".");
//$saldoak = number_format($saldoak);
//$dep = number_format(floatval($jumlah));
$result = $db->query("select nama from member where id_member='$id_member'");
$namar['nama'] = $result->row('nama');
$nama = $namar['nama'];
$resulthp = $db->query("select hp from member_hp where id_member='$id_member' LIMIT 1 OFFSET 0");
$hpr['hp'] = $resulthp->row('hp');
$nohp = $hpr['hp'];
//$now = 'NOW()';
$user = 'adminweb';
$data = array(
'id_member' => $this->input->post('id_member'),
'nama' => $nama,
'jml' => $this->input->post('jumlah'),
'saldo_awal' => $saldoaw,
'saldo_akhir' => $saldoak,
'kode_trx' => '1',
'status' => '1',
'ket' => $ket,
'user_input' => $user,
);
$db->set('tgl_transaksi', 'NOW()', FALSE);
$db->set('tgl_input', 'NOW()', FALSE);
return $db->insert('transaksi', $data);
$logsaldodata = array(
'id_member' => $this->input->post('id_member'),
'saldo' => $saldoaw,
'act' => $this->input->post('jumlah'),
'ket' => 'Deposit Tambah~True#',
);
$db->set('tgl', 'NOW()', FALSE);
$db->set('ref', 'last_insert_id()', FALSE);
return $db->insert('log_saldo', $logsaldodata);
}
}
Of course, you're returning before executing the rest of the code!
$db->set('tgl_input', 'NOW()', FALSE);
return $db->insert('transaksi', $data); // <-- remove the keyword here
$logsaldodata = array(
Remove that intermediate return statement, just leave $db->insert('transaksi', $data). return stops the function and returns the result, the rest of the function code won't be executed.
I am doing project using mongodb and php. so here I tried to rename existing database using php. so I did following way to rename database.
first I create new database( user new database name)
read all records from old db and insert to new db
then I drop old db
this is my code.
$conn = new \MongoClient('mongodb://example.com:27017', array("connect" => TRUE));
$exist_dbs = $conn->listDBs();
foreach ($exist_dbs["databases"] as $databse) {
if ($databse['name'] == $new_name) {
$new_name_is_exist = true;
}
}
if (!$new_name_is_exist) {
$db = new \MongoDB($conn, $old_name);
//create new database
$db_new = new \MongoDB($conn, $new_name);
$collections = $db->getCollectionNames();
foreach ($collections as $collection) {
//create collection
$new_collection = new \MongoCollection($db_new, $collection);
$mongo_collection = $db->$collection;
$objects = $mongo_collection->find();
while ($document = $objects->getNext()) {
//add records
$new_collection->insert($document);
}
}
$db->drop();
$msg = 'database renamed';
} else {
$msg = 'given database name already exist';
}
$conn->close();
it works fine. but I would like to know is there any better way to rename mongo database using php?
Copy db (php + mongodb):
<?php
$rename = 'oldname';
$name = 'newname';
$mongo = (new MongoClient());
$db = $mongo->admin;
$response = $db->command(array(
'copydb' => 1,
'fromhost' => 'localhost',
'fromdb' => $rename,
'todb' => $name
));
print_r($response);
Drop db (php + mongodb):
<?php
$name = 'oldname';
$mongo = (new MongoClient());
$db = $mongo->$name;
$response = $db->command(array(
'dropDatabase' => 1
));
print_r($response);
$db=new new Mongo();
Copy old_db to new_db
$responseCopy = $db->admin->command(array(
'copydb' => 1,
'fromhost' => 'localhost',
'fromdb' => 'old_db',
'todb' =>'new_db'
));
Now drop old_db
if($responseCopy['ok']==1){
$responseDrop=$db->old_db->command(array('dropDatabase' => 1));
//OR
$responseDrop =$db->old_db->drop();
}
Show Output
print_r($responseCopy);
print_r($responseDrop);
Output will be something like this
Array ( [ok] => 1 )
Array ( [dropped] => old_db [ok] => 1 )
you can use this
$mongo = new MongoClient('_MONGODB_HOST_URL_');
$query = array("renameCollection" => "Database.OldName", "to" => "Database.NewName", "dropTarget" => "true");
$mongo->admin->command($query);