PHP don't generate properly array from database (UBUNTU) - mysql

I have a little problem.
There are two tables in my database: users and classes. The first one contains info about users, and the second one - about user classes and about access rights.
Now I'm extracting all data from there using this:
SELECT * FROM users NATURAL JOIN classes WHERE users.ID_User = '$id';
The mysql code works and returns a right array.
Now, when I'm doing next:
<?php
$result = mysql_query($sql_above);
$row = mysql_fetch_array($result);
print_r($row);
?>
... i'm getting this:
Array ( [0] => 1 [ID_User] => 1 [1] => John [Name] => John [2] => Doe [Surname] => Doe [3] => ... [16] => Owner [Class] => Owner [17] => [All] => [18] => [CanAuth] => [19] => [CanViewData] => [20] => [CanAddData] => [21] => [CanAlterData] => [22] => [CanDeactivateData] => [23] => [CanDeleteData] => [24] => [CanMgLocatari] => ... )
Columns from 17 till the end are access rights, noted in the database by 1 or 0. And there, they're missing.
Is there any option to enable in PHP configuration to correct this thing? Because on a Windows machine, the code executes properly and rights are working.
PHP Version 5.3.6-13ubuntu3.7 | Apache/2.2.20 (Ubuntu) | MySQL client version: 5.1.62
Please, reply. Thanks!

Related

Global Payments HPP sandbox. 508 Invalid characters in MERCHANT_RESPONSE_URL when ngrok is used

Is there any chance to get working the Global Payments HPP sandbox with ngrok?
Currently, it gives
508
Invalid characters in MERCHANT_RESPONSE_URL. Please contact the merchant.
for an URL like
https://testsitewww.ap.ngrok.io/~testsite/shop/src/cart.php?target=callback&txn_id_name=txnId&txnId=000008-567H
The full request
(
[ORDER_ID] => testsite2_000008-567H
[MERCHANT_ID] => dev240640823746370784
[TIMESTAMP] => 20201110125116
[ACCOUNT] =>
[AUTO_SETTLE_FLAG] => 1
[HPP_VERSION] => 2
[AMOUNT] => 13999
[HPP_CUSTOMER_PHONENUMBER_MOBILE] =>
[HPP_CUSTOMER_EMAIL] => testsite+test#example.com
[HPP_SHIPPING_POSTALCODE] => 90001
[HPP_SHIPPING_COUNTRY] => 643
[HPP_SHIPPING_CITY] => Los Angeles
[HPP_SHIPPING_STREET1] => test
[HPP_SHIPPING_STREET2] =>
[HPP_SHIPPING_STREET3] =>
[HPP_BILLING_POSTALCODE] => 90001
[HPP_BILLING_COUNTRY] => 643
[HPP_SHIPPING_STATE] =>
[HPP_BILLING_CITY] => Los Angeles
[HPP_BILLING_STREET1] => test
[HPP_BILLING_STREET2] =>
[HPP_BILLING_STREET3] =>
[HPP_ADDRESS_MATCH_INDICATOR] => TRUE
[MERCHANT_RESPONSE_URL] => https://testsitewww.ap.ngrok.io/~testsite/shop/src/cart.php?target=callback&txn_id_name=txnId&txnId=000008-567H
[COMMENT1] => Test company
[CURRENCY] => USD
[SHA1HASH] => e068e2876262d61f22c84f440463fcdb1b42f90a
)
other URLs work correctly.
According to https://developer.globalpay.com/contact-us
I have to ask integration questions here
I think the character ~ in URL is causing the issue here, and not ngrok.
I have just used nrok for the same, it works fine. My url looks something like: http://6c59460.ngrok.io/realexresponse
Also, ngrok points to a local IIS url like http://localhost:88. So effectively, the URL I am supplying in MERCHANT_RESPONSE_URL is http://localhost:88/realexresponse
I found this article suggesting to not use some characters in URL, as they may be reserved by the server or in this case Realex. One of them is ~
https://help.dragonmetrics.com/en/articles/213986-invalid-characters-in-url

AutoIncrement PK incrementing irregularry

I recently release an app: https://my.kendozone.com in Laravel 5.3 / MySQL
I'm getting users, but one weird thing is that my user's id are not incrementing by one.
HERE last 10 rows id :
5401
5402
5403
5404
5405
5406
5407
5408
8359
9799
The 2 ways I save my users are :
$user = User::create([
'provider' => $provider,
'provider_id' => $userData->id,
'name' => $userData->name,
'firstname' => $userData->name,
'slug' => str_slug($userData->name),
'email' => $userData->email,
'avatar' => $avatar,
'role_id' => config('constants.ROLE_USER'),
'verified' => 1,
]);
or
$user = User::create(['name' => $request->name,
'email' => $request->email,
'password' => bcrypt($request->password),
'role_id' => config('constants.ROLE_USER'),
'verified' => 1,
]);
How should understand this??? Is it normal???
Does anybody have an explanation???
My id are weird because of my Functional tests.
when running, they use :
use DatabaseTransactions
that mean that all queries runs into a Transaction, but I guess it uses ids range.

foreach on json data

Hi i want to insert values into table which is posted from api
json data is
{"questions":{"34":"Yes", "46":"good", "48":"NA", "29":"Yes", "45":"ravi", "49":"Negative", "43":"1 BHK", "35":"Neighbour", "38":"14", "39":"9", "27":"1",
"41":"Married", "52":"vijay#123.com", "47":"good", "31":"Bunglow", "33":"Middle Class", "37":"Owned By Parents", "30":"good", "50":"easy",
"51":"comments", "32":"No", "44":"[MusicSystem,PC,Refrigerator,Airconditioner]"}}
when i convert into array it is
Array
(
[questions] => Array
(
[34] => Yes
[46] => good
[48] => NA
[29] => Yes
[45] => ravi
[49] => Negative
[43] => 1 BHK
[35] => Neighbour
[38] => 14
[39] => 9
[27] => 1
[41] => Married
[52] => ravi#gmail.com
[47] => good
[31] => Bunglow
[33] => Middle Class
[37] => Owned By Parents
[30] => good
[50] => easy
[51] => comments
[32] => No
[44] => [MusicSystem,PC,Refrigerator,Airconditioner]
)
)
how to get this values like
using foreach
$question=34;
$answer= yes;
Try like this.Convert json into array using json_decode().And make a new array with key and value.Then just print the first key and value.
<?php
$json = '{"questions":{"34":"Yes", "46":"good", "48":"NA", "29":"Yes", "45":"ravi", "49":"Negative", "43":"1 BHK", "35":"Neighbour", "38":"14", "39":"9", "27":"1",
"41":"Married", "52":"vijay#123.com", "47":"good", "31":"Bunglow", "33":"Middle Class", "37":"Owned By Parents", "30":"good", "50":"easy",
"51":"comments", "32":"No", "44":"[MusicSystem,PC,Refrigerator,Airconditioner]"}}
';
$array = json_decode($json,TRUE);
//print_r($array);
foreach($array['questions'] as $key=>$value)
{
$arr[] = array('key'=>$key,'value'=>$value);
}
//print_r($arr);
echo "Question:".$arr[0]['key'].PHP_EOL;
echo "Answer:".$arr[0]['value'];
Output:
Question:34
Answer:Yes
To access a single value while having the key, you can do $array["questions"][34] to get the answer yes.
If you want to loop through all of them, you can do this loop:
foreach($array["questions"] as $no => $ans){
echo "Question: $no";
echo "Answer: $ans";
}

Magento SOAP API V2 calls not working for Private Sales Store (Authorization plugin used)

FACTS:
I am not very good at magento but have some experience working with API's using PHP.
TARGET:
What I actually want to do is
Download magento customer orders in our order system
Process the orders
Upload tracking code back to magento
Update magento products level based on the values fetched from our local Stock System running on a different server
ENVIRONMENT:
I am using a Login Plugin to make the store private so only customers with an account can access it.
PROBLEM:
IF 'AUTHENTICATION' PLUGIN IS DISABLED EVERYTHING WORKS FINE. BUT WHEN PLUGIN IS ENABLED STEP 3 AND 4 STOP WORKING.
ERROR SAMPLE:
Magento SOAP API V2 calls result in
SoapFault Object ( [message:protected] => looks like we got no XML document, when used for Private Sales store. I am able to login using API a/c,fetch orders but calls to update stock / upload tracking etc fail.
SAMPLE OUTPUT:
Login Successful [0a254c064fa033859bc75db94]
Request :
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento"><SOAP-ENV:Body><ns1:catalogInventoryStockItemUpdateRequestParam>sessionId>0a254c064fa033859bc75db94</sessionId><productId>1</productId><data><qty>100</qty><is_in_stock>1</is_in_stock></data></ns1:catalogInventoryStockItemUpdateRequestParam></SOAP-ENV:Body></SOAP-ENV:Envelope>
Result:
SoapFault Object ( [message:protected] => looks like we got no XML document [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/vhosts/XXX/magentoAPI/stock.php [line:protected] => 31 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/vhosts/XXX/magentoAPI/stock.php [line] => 31 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => catalogInventoryStockItemUpdate [1] => Array ( [0] => stdClass Object ( [sessionId] => 0a254c064fa033859bc75db94 [productId] => 1587 [data] => Array ( [qty] => 1000 [is_in_stock] => 1 ) ) ) ) ) [1] => Array ( [file] => /var/www/vhosts/XXX/magentoAPI/stock.php [line] => 31 [function] => catalogInventoryStockItemUpdate [class] => SoapClient [type] => -> [args] => Array ( [0] => stdClass Object ( [sessionId] => 0a254c064fa033859bc75db94 [productId] => 1587 [data] => Array ( [qty] => 1000 [is_in_stock] => 1 ) ) ) ) ) [previous:Exception:private] => [faultstring] => looks like we got no XML document [faultcode] => Client [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ )

Joins - Merge result into single, multidimensional array

I'm performing a simple query that joins two tables together. What I get is something like this.
array(
[0] => array(
'id' => 52
'name' => 'charles',
'sale_id' => 921,
'sale_time' => 1306393996,
'sale_price' => 54.21
),
[1] => array(
'id' => 52
'name' => 'charles',
'sale_id' => 922,
'sale_time' => 1306395000,
'sale_price' => 32.41
),
...
);
...which is the expected result. However, I'd like the query to return something like this:
array(
[0] => array(
'id' => 52,
'name' => 'charles',
'sales' => array(
[0] => array(
'sale_id' => 921,
'sale_time' => 1306393996,
'sale_price' => 54.21
),
[1] => array(
'sale_id' => 922,
'sale_time' => 1306395000,
'sale_price' => 32.41
),
...
)
)
)
Now I realize I could simply perform two queries, one for the user info, and another for sales, and merge those arrays together using whatever language I'm using (PHP in this case). But I have many arrays of properties and querying and merging for those seems awfully inelegant to me (although it does work). It seems to me there'd be a way to work with a single, unified object without duplicating data.
Just wondering if there was a no-brainer query, or if that's simply not easy through MySQL alone.
I would say this is not possible with MySQL alone - you have to do some tricks at application level. That is, because even if you send a single query that will bring you all the data from MySQL to your application (PHP), they will come as a denormalized array of data - your first case.
If you want to get the data as in your second case, I'd recommend using some ORM - in Ruby there is ActiveRecord, in Perl there are Class::DBi, DBIx::Class and many more - I can not name one for PHP that is able to do this, but I am sure there are plenty.