I have an issue with a SQL Server column quote number which not accept more than 5 digits. 5 digits or below it is working fine, but above 5 digits, it is causing an error:
xx.xx.xx.xx didn’t send any data.
ERR_EMPTY_RESPONSE
Example - quote number 12345 is working fine, but 123456 causes the error.
I have also changed bindParam to bindValue in query but not result.
Connection:
try {
$proconn = new PDO("dblib:host=$servername;dbname=TableQuote;charset=UTF-8", $username, $password);
// set the PDO error mode to exception
$proconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed" . $e->getMessage;
}
Variable data:
//$quote_number="123456";
[quote_noumber] => '12345'
[inside_sales] => 'Pat Zerphy'
[outside_sales] => 'SEL102'
[customer_code] => 'SEL101'
[custome_name] => 'Selex Systems Inegrations'
[customer_contact] => 'Bob Smith'
[quote_details] => 'Misc coax cable assemblies.
1/2" Superflex, 1/4" Superflex'
[rna_location] => '1'
[number_of_line_items] => '25'
[created] => '1468291705'
Insert query:
try {
$prosql = $proconn->prepare("insert into dbo.QuoteRecord(quote_number,customer_code,customer_name,rna_location,inside_sale,outside_sale,customer_contact,quote_detail,number_of_line_items,created)VALUES(:quote_number,:customer_code,:customer_name,:rna_location,:inside_sale,:outside_sale,:customer_contact,:quote_detail,:number_of_line_items,:created)");
$prosql->bindParam(':quote_number',$quote_number);
$prosql->bindParam(':customer_code',$customer_code);
$prosql->bindParam(':customer_name',$customer_name);
$prosql->bindParam(':rna_location',$rna_location);
$prosql->bindParam(':inside_sale',$inside_sale);
$prosql->bindParam(':outside_sale',$outside_sale);
$prosql->bindParam(':customer_contact',$customer_contact);
$prosql->bindParam(':quote_detail',$quote_detail);
$prosql->bindParam(':number_of_line_items',$number_of_line_items);
$prosql->bindParam(':created',$created);
$prosql->execute();
}
catch ( PDOException $e ) {
print( "Error connecting to SQL Server." );
die(print_r($e));
}
Data types:
Array
(
[TABLE_CATALOG] => TableQuote
[0] => proALPHA
[TABLE_SCHEMA] => dbo
[1] => dbo
[TABLE_NAME] => QuoteRecord
[2] => QuoteRecord
[COLUMN_NAME] => quote_number
[3] => quote_number
[ORDINAL_POSITION] => 2
[4] => 2
[COLUMN_DEFAULT] =>
[5] =>
[IS_NULLABLE] => YES
[6] => YES
[DATA_TYPE] => varchar
[7] => varchar
[CHARACTER_MAXIMUM_LENGTH] => 128
[8] => 128
[CHARACTER_OCTET_LENGTH] => 128
[9] => 128
[NUMERIC_PRECISION] =>
[10] =>
[NUMERIC_PRECISION_RADIX] =>
[11] =>
[NUMERIC_SCALE] =>
[12] =>
[DATETIME_PRECISION] =>
[13] =>
[CHARACTER_SET_CATALOG] =>
[14] =>
[CHARACTER_SET_SCHEMA] =>
[15] =>
[CHARACTER_SET_NAME] => iso_1
[16] => iso_1
[COLLATION_CATALOG] =>
[17] =>
[COLLATION_SCHEMA] =>
[18] =>
[COLLATION_NAME] => SQL_Latin1_General_CP1_CI_AS
[19] => SQL_Latin1_General_CP1_CI_AS
[DOMAIN_CATALOG] =>
[20] =>
[DOMAIN_SCHEMA] =>
[21] =>
[DOMAIN_NAME] =>
[22] =>
)
Example - quote number - 12345 working fine but 123456 it giving
error.
if that's the case then most probably it's because of the column size definition for column quote_number. Looks like it's a VARCHAR column and if it is still not wrong you have set its size to VARCHAR(5) probably.
Post your table definition or schema for dbo.QuoteRecord table.
Related
It is my first time working with an external API. I have already fixed that it gives me the right output. In a controller I have the following code:
public function index() {
$api = new Wefact();
$parameters = [
];
$api_response = $api->sendRequest('product', 'list', $parameters);
print_r($api_response);
}
This shows me the array on the page. But I do not know how to use this array to get it into a foreach in the blade. The output of the print_r is as follow:
Array
(
[controller] => product
[action] => list
[status] => success
[date] => 2022-05-05T04:20:03+02:00
[totalresults] => 2
[currentresults] => 2
[offset] => 0
[products] => Array
(
[0] => Array
(
[Identifier] => 1
[ProductCode] => P0001
[ProductName] => SIM ONLY 5GB
[ProductKeyPhrase] => SIM ONLY 5GB
[ProductDescription] =>
[NumberSuffix] =>
[PriceExcl] => 25
[TaxCode] => V21
[TaxPercentage] => 21
[PricePeriod] => m
[Modified] => 2022-05-05 03:49:57
)
[1] => Array
(
[Identifier] => 2
[ProductCode] => P0002
[ProductName] => SIM ONLY 10GB
[ProductKeyPhrase] => SIM ONLY 10GB
[ProductDescription] =>
[NumberSuffix] =>
[PriceExcl] => 35
[TaxCode] => V21
[TaxPercentage] => 21
[PricePeriod] => m
[Modified] => 2022-05-05 04:03:47
)
)
)
As you can see there are two products. I want to have these in a datatable with an foreach.
Since it is my first time, I really do not know how to do this.
Anyone that can help me out?
If you want to access the array of products it would be like this
return view('your_view', [
'products' => $api_response['products']
]);
I'm cakephp learner and working on a project.
I have a problem. I did google but unable to find the right solution. I hope, I can find the solution here.
Here is My Code.
function getCompanySales(){
$model=ClassRegistry::init('Customer');
$modelcompany=ClassRegistry::init('Company');
$from = date("Y-m")."-01 00:00:00";
$days_in_month = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
$to = date("Y-m")."-".$days_in_month." 24:00:00";
$companyname=$modelcompany->find('all');
$companiessales=$model->find('all',array(
'conditions' => array(
"AND" =>array(
"Customer.created >=" => $from,
"Customer.created <=" => $to
)
),
'recursive'=>-1
)
);
return $companiessales;
} // Get Company list
and I'm getting result like
Array (
[0] => Array ( [Customer] => Array ( [gateway] => 10 [amount] => 349 ) )
[1] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 150 ) )
[2] => Array ( [Customer] => Array ( [gateway] => 13 [amount] => 349 ) )
[3] => Array ( [Customer] => Array ( [gateway] => 10 [amount] => 350 ) )
[4] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 100 ) )
[5] => Array ( [Customer] => Array ( [gateway] => 9 [amount] => 299 ) )
[6] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 249 ) )
[7] => Array ( [Customer] => Array ( [gateway] => 10 [amount] => 249 ) )
[8] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 299 ) )
[9] => Array ( [Customer] => Array ( [gateway] => 12 [amount] => 199 ) )
[10] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 150 ) ) )
But I want to Sum the Value with same gateway like
array(
[7] => 948 //sum of gateway 7
[9] => 299 //sum of gateway 9
[10] => 948 //sum of gateway 10
[12] => 199 //sum of gateway 12
[13] => 349 //sum of gateway 13
)
In another query =>
array(
[7] => company 1
[9] => company 2
[10] => company 3
[12] => company 4
[13] => company 5
)
I want a final result as
array(
[company1] => 948
[company1] => 299
[company1] => 948
[company1] => 199
[company1] => 349
)
Thanks for all your help. I'm sure I'll get the easy steps to resolve the issue.
Thanks for stackoverflow to give me ideas and find out an solutions.
I, first find the customer list by sum the amount and group by gateway by bellow code.
in the view use the custom helper to get the name by id. that's what , I was looking for.
$companiessales=$model->find('all',array(
'fields'=>array(
'SUM(amount) AS amount',
'gateway'
),
'group' => 'Customer.gateway',
'conditions' => array(
"AND" =>array(
"Customer.created >=" => $from,
"Customer.created <=" => $to
)
),
'recursive'=>-1
)
);
Here is the code to get the gateway name by id (which we are making primary id by grouping them)..
function getGatewayName($id){
$model=ClassRegistry::init('Gateway');
$companiess=$model->find('first',array(
'fields'=>array('fullname'),
'conditions'=>array(
'Gateway.id' => $id,
),
'recursive'=>-1
)
);
$name=$companiess['Gateway']['fullname'];
return $name;
} // Get Payment Gateway Name
The print_r returns the following value:
[cobrancas] => Array
(
[0] => stdClass Object
(
[id] => 749205
[nossonumero] => 3189028
[dataemissao] => 1395284400
[datavencimento] => 1395370800
[datapagamento] => 1395284400
[dias_vencidos] => 788
[mora] => 0.23225806451613
[multa] => 1.8
[valor] => 90.00
[valorpago] => 88.57
[valordesconto] => 0.00
[jurosmora] => 0.00
[banco] => 33
[agencia] => 1525
[dac_agencia] => 0
[conta] => 013000045
[dac_conta] => 2
[carteira] => 201
[nome_empresa] => STOCK MIDIA INF. LTDA
[cod_cedente] => 1640348
)
But as I know it gives me values of up to [ 50 ] up. How do I know the print me just [VALOR ] above 100.00 ???
$Arr = count($cliente->cobrancas);
i I have a problem to print array .I received this array of web services by nusoap
How can I display the values of this multidimensional array. I worked with foreach, I could not do it., Please explain with an example. Thanks
my array:
Array ( [Result] => Array ( [Root] => Array ( [row] => Array ( [0] => Array ( [!R] => 0 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 91 ) [1] => Array ( [!R] => 19 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 92 ) [2] => Array ( [!R] => 38 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 93 ) [3] => Array ( [!R] => 57 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] => name3 [!C8] => name3 ) ) ) ) )
I am having a problem with my HABTM updates in CakePHP 1.3.
First off, here is the relationship declaration as it appears in the Alert model:
var $hasAndBelongsToMany = array(
'Region' => array(
'className' => 'Region',
'joinTable' => 'alerts_regions',
'foreignKey' => 'alert_id',
'associationForeignKey' => 'region_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'ForecastZone' => array(
'className' => 'ForecastZone',
'joinTable' => 'alerts_forecast_zones',
'foreignKey' => 'alert_id',
'associationForeignKey' => 'forecast_zone_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
When I submit my form to create a record for the model everything works fine and the associated models (HABTM tables) get the proper records created. $this->data looks like this:
Array
(
[Alert] => Array
(
[title] => Test Alert
[overview] => This is a test alert overview
[user_id] => 3
[timeframe] => Tonight
[effective] => 2012-07-05 18:00:00
[effective_time] => 6:00
[effective_ampm] => pm
[expires] => 2012-07-05 21:00:00
[expires_time] => 9:00
[expires_ampm] => pm
)
[Region] => Array
(
[Region] => Array
(
[0] => 6
[1] => 5
)
)
[ForecastZone] => Array
(
[ForecastZone] => Array
(
[0] => 1598
[1] => 1594
[2] => 2685
[3] => 1565
[4] => 1613
[5] => 1595
)
)
)
Now, because of the complex associations with this Model (Alert, ForecastZone, and Region) I have it set up so there is a separate interface on the Alerts/Edit page to update JUST the forecast zones. The Alerts controller figures out what Regions the Forecast Zones belong to, and the controller populates the [Region][Region] value on it's own. The ForecastZones are selected from an interface where the user clicks to select which zones they want.
When I submit a form to the /alerts/edit action, I can save the Alert data (title, overview, etc) no problem. However, it is IMPOSSIBLE for me to get the related HABTM models to update. I am at the verge of just doing it all with $this->query() but I am going to try one last time to figure out what is going wrong.
Here is what the form looks like when I submit to /alerts/edit:
Array
(
[Alert] => Array
(
[id] => 37
[fcz_update] => true
)
[Region] => Array
(
[Region] => Array
(
[0] => 6
[1] => 5
)
)
[ForecastZone] => Array
(
[ForecastZone] => Array
(
[0] => 1595
[1] => 1613
[2] => 1565
[3] => 2685
[4] => 1594
[5] => 1598
[6] => 2989
[7] => 3723
[8] => 1650
[9] => 1626
[10] => 1653
[11] => 1678
[12] => 3447
[13] => 1649
[14] => 1654
[15] => 1675
[16] => 3448
[17] => 1668
[18] => 1664
[19] => 1635
[20] => 1667
[21] => 1628
)
)
)
I have tried $this->Alert->save($this->data) as well as $this->Alert->saveAll($this->data) and neither of these work. Both save() functions return a 1 (true) so I assume they are successful... yet when I return to my recently edited records... nothing has changed. I tried adding all of the other Alert data into the form as hidden fields, so I could save the whole alert data at once... this does not work either.
Edit:
Here is the code from my alerts_controller.php edit function/action that performs the save operations:
if (!empty($this->data)) {
//If we are updating forecast zones
if(array_key_exists('fcz_update',$this->data['Alert'])){
$fcz_str = $this->data['Alert']['AlertForecastZone'];
$forecast_zones = explode(',',$fcz_str);
$fcz_regions = $this->ForecastZone->query('SELECT DISTINCT region_id FROM forecast_zones WHERE id IN (' . $fcz_str . ') AND region_id != 0;');
if(!empty($fcz_regions)){
foreach($fcz_regions as $fczr){ $alert_regions[] = $fczr['forecast_zones']['region_id']; }
$this->data['Region']['Region'] = $alert_regions;
}
$this->data['ForecastZone']['ForecastZone'] = $forecast_zones;
unset($this->data['Alert']['AlertForecastZone']);
//debug($this->data);
$this->Alert->save($this->data);
//Go back to alert edit to review changes
$this->redirect($this->referer());
}
}
The best bugs are the ones that throw no errors or have any way for you to figure out what's going wrong. So angry and frustrated... please help.
Play with the keying of your data.
Try [ForecastZone][0] => 1595
or
[ForecastZone][0][id] => 1595
or even
[ForecastZone][0][ForecastZone] => 1595
I always got to fight to remember what the correct keying order is for the HABTM
To save associated and related data you need to use the saveAll function $this->Alert->saveAll($this->data)