text in result instead of number returns mysqli unknown column error - mysqli

print_r($cfs);
Array (
[0] => Array ( [0] => MST Ice P [1] => MST [2] => Ice )
[1] => Array ( [0] => MST Ice P [1] => MST [2] => Ice )
[2] => Array ( [0] => MST 298 P [1] => MST [2] => 298 )
[3] => Array ( [0] => MST Ice P [1] => MST [2] => Ice )
[4] => Array ( [0] => MST 302 P [1] => MST [2] => 302 )
)
here is my mysqli:
for($i = 0; $i < count($cfs); $i++)
{
$con->query(
"UPDATE gages SET cfs = {$cfs[$i][2]}, modtime = now() WHERE usgs =
{$stano[$i][1]}")
or die($con->error);
}
Here is my error:
Unknown column 'Ice' in 'field list'
This works fine in the summer when there in no ice.

If as you say the cfs column is VARCHAR then it should have been coded like this with single quotes around the value.
I dont see how it ever worked without them.
for($i = 0; $i < count($cfs); $i++) {
$con->query("UPDATE gages
SET cfs = '{$cfs[$i][2]}',
modtime = now()
WHERE usgs = {$stano[$i][1]}")
or die($con->error);
}

Related

I have a really confusing issue with checkboxes

I have a problem with the value that checkboxes returns to me:
first of all i start with that 2 variables:
$blabla_severity_levels =
variable_get('blabla_severity_levels', array());
$blabla_severity_options = array();
then i make a for each for the watchdogs:
foreach (watchdog_severity_levels() as $severity_numbers => $severity) {
$blabla_severity_options[$severity_numbers] = check_plain(drupal_ucfirst($severity));
}
then i generate the form:
$blabla_form['blabla_severity_levels'] = array(
'#type' => 'checkboxes',
'#title' => t('Type of log messages'),
'#options' => $blabla_severity_options,
'#default_value' => array_values($blabla_severity_levels),
'#required' => TRUE,
);
return system_settings_form($blabla_form);
and in my function i call it like:
$severity_levels = variable_get('blabla_severity_levels', array());
now if i make a dpm($severity_levels)
it gets me out an array with
error (String, 5 characters ) error
warning (String, 7 characters ) warning
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
notice (Integer) 0
info (Integer) 0
debug (Integer) 0
but i am really needing is the blabla_severity_options which is:
error (String, 5 characters ) 3
warning (String, 7 characters ) 4
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
notice (Integer) 0
info (Integer) 0
debug (Integer) 0
I want to save the values...... any ideas plz?? i really need help

phpseclib asn1 parser issue with MS cert SAN

I am attempting to parse some M$ generated certs and finding that the phpseclib ASN1 decodeBER function is choking on some OID's. I would really like to understand this function better and its behavior in this case.
Here is an example cert for discussion:
-----BEGIN CERTIFICATE-----
MIIG1jCCBL6gAwIBAgITUAAAAA0qg8bE6DhrLAAAAAAADTANBgkqhkiG9w0BAQsF
ADAiMSAwHgYDVQQDExcuU2VjdXJlIEVudGVycHJpc2UgQ0EgMTAeFw0xNTAyMjMx
NTE1MDdaFw0xNjAyMjMxNTE1MDdaMD8xFjAUBgoJkiaJk/IsZAEZFgZzZWN1cmUx
DjAMBgNVBAMTBVVzZXJzMRUwEwYDVQQDEwxtZXRhY2xhc3NpbmcwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDMdG1CzR/gTalbLN9J+2cvMGeD7wsR7S78
HU5hdwE+kECROjRAcjFBOR57ezSDrkmhkTzo28tj0oAHjOh8N9vuXtASfZSCXugx
H+ImJ+E7PA4aXBp+0H2hohW9sXNNCFiVNmJLX66O4bxIeKtVRq/+eSNijV4OOEkC
zMyTHAUbOFP0t6KoJtM1syNoQ1+fKdfcjz5XtiEzSVcp2zf0MwNFSeZSgGQ0jh8A
Kd6YVKA8ZnrqOWZxKETT+bBNTjIT0ggjQfzcE4zW2RzrN7zWabUowoU92+DAp4s3
sAEywX9ISSge62DEzTnZZSf9bpoScAfT8raRFA3BkoJ/s4c4CgfPAgMBAAGjggLm
MIIC4jAdBgNVHQ4EFgQULlIyJL9+ZwAI/SkVdsJMxFOVp+EwHwYDVR0jBBgwFoAU
5nEIMEUT5mMd1WepmviwgK7dIzwwggEKBgNVHR8EggEBMIH+MIH7oIH4oIH1hoG5
bGRhcDovLy9DTj0uU2VjdXJlJTIwRW50ZXJwcmlzZSUyMENBJTIwMSxDTj1hdXRo
LENOPUNEUCxDTj1QdWJsaWMlMjBLZXklMjBTZX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XX5qt+tEDvYfSlFcc
0lv3aQnV/eIdfm7APJkQ3lmNWWQwdkVf7adXJ7KAAPHSt1yvSbVxThJR/jmIkyeQ
XW/TOP5m7JI/GrmvdlzI1AgwJ+zO8fOmCDuif99pDb1CvkzQ65RZ8p5J1ZV6hzlb
VvOhn4LDnT1jnTcEqigmx1gxM/5ifvMorXn/ItMjKPlb72vHpeF7OeKE8GHsvZAm
osHcKyJXbTIcXchmpZX1efbmCMJBqHgJ/qBTBMl9BX0+YqbTZyabRJSs9ezbTRn0
oRYl21Q8EnvS71CemxEUkSsKJmfJKkQNCsOjc8AbX/V/X9R7LJkH3UEx6K2zQQKK
k6m17mi63YW/+iPCGOWZ2qXmY5HPEyyF2L4L4IDryFJ+8xLyw3pH9/yp5aHZDtp6
833K6qyjgHJT+fUzSEYpiwF5rSBJIGClOCY=
-----END CERTIFICATE-----
For simple testing purposes this is my driver:
$X509 = new File_X509();
$BER = $X509->_extractBER($BER);
$ASN1 = new File_ASN1();
$ASN1->loadOIDs($X509->oids);
$DECODED = $ASN1->decodeBER( $BER );
Utility::dumper($DECODED);
I think we are running into trouble ~line 423:
case FILE_ASN1_TYPE_OCTET_STRING:
if (!$constructed) {
$current['content'] = $content;
} else {
$current['content'] = '';
$length = 0;
while (substr($content, 0, 2) != "\0\0") {
$temp = $this->_decode_ber($content, $length + $start);
$this->_string_shift($content, $temp['length']);
// all subtags should be octet strings
//if ($temp['type'] != FILE_ASN1_TYPE_OCTET_STRING) {
// return false;
//}
$current['content'].= $temp['content'];
$length+= $temp['length'];
}
if (substr($content, 0, 2) == "\0\0") {
$length+= 2; // +2 for the EOC
}
}
break;
Specifically in dumping the output of array element 7 (subjectAltName)
[7] => Array
(
[start] => 1104
[headerlength] => 2
[type] => 16
[content] => Array
(
[0] => Array
(
[start] => 1106
[headerlength] => 2
[type] => 6
[content] => 2.5.29.17
[length] => 5
)
[1] => Array
(
[start] => 1111
[headerlength] => 2
[type] => 4
[content] => 0% #^F+^F^A^D^A^Â7^T^B^C ^U^L^Smetaclassing#secure
[length] => 41
)
)
[length] => 48
)
It appears that the content should be parsed into an array instead of a string of binary junk. I believe it should parse into something more like this:
SEQUENCE(2 elem)
OBJECT IDENTIFIER2.5.29.17
OCTET STRING(1 elem)
SEQUENCE(1 elem)
Offset: 1113
Length: 2+37
(constructed)
Value:
(1 elem)
[0](2 elem)
OBJECT IDENTIFIER1.3.6.1.4.1.311.20.2.3
[0](1 elem)
UTF8String metaclassing#secure
I believe this is a "constructed" field, however up at line ~298 the bitwise operation happening is a little beyond my understanding:
$constructed = ($type >> 5) & 1;
I have written a corner-case matching hex values to force $constructed to 1 for this specific array element but didnt see much of an improvement in parsing. Wondering what the next best step is to remedy this? I really appreciate your help and thoughts. Thanks!
you should attempt to recurse OCTET_STRING contents and attempt to decode the nested record to see if it decodes as valid ASN.1. All certificate extension values are placed as a nested to OCTET_STRING structure:
From what I know, the following primitive tags are used in primitive form only: BOOLEAN, INTEGER, NULL, OBJECT_IDENTIFIER, REAL, ENUMERATED and RELATIVE_OID. The rest primitive tags may have embedded content. Although, this list is not definitive, OCTET_STRING definitely may be a container even if its tag is encoded in a primitive form. This applies to BIT_STRING as well.
Yes indeed, the code should recur. Here are my findings thus far:
$class = ($type >> 6) & 3;
The issue does appear to be the bitwise operation being used, it is not correctly identifying class (is returning 0 for application when it should be 2 for context specific and 0 for constructed which should be 1.
To test I inserted this code below (really hackish, but im an ASN.1n00b:
// Manual testing for incorrect class/constructed detection!
if ( !$constructed && $class == 0 && isset($content[0]) && isset($content[1]) )
{
//print "\nSTART: $start\tTYPE IS: {$type}\t CLASS IS: {$class}\tCONTENT IS {$content}\n";
if ( ($content[0] == "0" && $content[1] == "%" ) ||
($content[0] == hex2bin("30") && $content[1] == hex2bin("81") ) ||
($content[0] == hex2bin("82") && $content[1] == hex2bin("01") ) ||
($content[0] == hex2bin("30") && $content[1] == hex2bin("20") ) ||
($content[0] == hex2bin("1e") && $content[1] == hex2bin("08") ) ||
($content[0] == hex2bin("00") && $content[1] == hex2bin("55") ) ||
($content[0] == hex2bin("04") && $content[1] == hex2bin("14") ) ||
($content[0] == hex2bin("30") && $content[1] == hex2bin("16") ) ||
($content[0] == hex2bin("00") && $content[1] == hex2bin("30") ) )
{
$class = 2; $constructed = 1; //print "SET CLASS AND CONSTRUCTED!\n";
}else{
//print "C0: {$content[0]} = (0x" . bin2hex($content[0]) . ") C1: {$content[1]} = (0x" . bin2hex($content[1]) . ") did not match!\n";
}
}
And indeed, manually matching the bytes not correctly detected does resolve my issue:
[7] => Array
(
[start] => 1104
[headerlength] => 2
[type] => 16
[content] => Array
(
[0] => Array
(
[start] => 1106
[headerlength] => 2
[type] => 6
[content] => 2.5.29.17
[length] => 5
)
[1] => Array
(
[type] => 2
[constant] => 4
[content] => Array
(
[0] => Array
(
[start] => 1113
[headerlength] => 2
[type] => 16
[content] => Array
(
[0] => Array
(
[type] => 2
[constant] => 0
[content] => Array
(
[0] => Array
(
[start] => 1117
[headerlength] => 2
[type] => 6
[content] => 1.3.6.1.4.1.311.20.2.3
[length] => 12
)
)
[length] => 14
[start] => 1115
[headerlength] => 2
)
[1] => Array
(
[type] => 2
[constant] => 0
[content] => Array
(
[0] => Array
(
[start] => 1131
[headerlength] => 2
[type] => 12
[content] => metaclassing#secure
[length] => 21
)
)
[length] => 23
[start] => 1129
[headerlength] => 2
)
)
[length] => 39
)
)
[length] => 41
[start] => 1111
[headerlength] => 2
)
)
[length] => 48
)
At this point I think I need to wait for the library developers to review the ASN.1 parsing function/library and review why these certs make it so incredibly unhappy. Patching this is somewhat beyond my capabilities at the moment.

MongoDB does not return all points in MaxDistance

I have this search query in php:
[$near] => Array(
[0] => -73.5539925
[1] => 45.5086699
)
[$maxDistance] => 0.269978401728
0.269978401728 was calculated this way: 30/111.12
problem is that it doesn't find point with these values: -73.8260706 45.4293058
it finds it only if distance is increased to 32.
If I check gmap walking distance between these points is 26.6 which is longer than direct line. Then even with 25km it should probably work, but now it doesnt work with 30.
Do I miss something?
Thanks
I changed query to use within instead of near and now it works fine
$radiusOfEarth = 6378.1;//radius in km
$calculated_distance = (float) $distance / $radiusOfEarth;
$search = array(
'loc' => array('$within' =>
array('$centerSphere' =>
array(
array(floatval($lng), floatval($lat)), $calculated_distance
)
)
)
);
or
[loc] => Array
(
[$within] => Array
(
[$centerSphere] => Array
(
[0] => Array
(
[0] => -73.5539925
[1] => 45.5086699
)
[1] => 0.00501716812217
)
)
)

Extract Cumulative N-grams Matlab

I have an array of words:
x=['ae' ; 'be' ; 'ce' ; 'de' ; 'ee' ; 'fe']
I would like to extract sets of characters. So assume each set has N = 2 words, how can I go about getting return values that look like this
'ae' 'be'
'be' 'ce'
'ce' 'de'
'de' 'ee'
'ee' 'fe'
So if N = 2, I get back a matrix where each row contains pairs of the current and previous characters. If N=3 i will get back current and previous 2 chars for each row. I want to avoid loops if possible.
Any ideas?
You can use the Circulant Matrix Maltlab provides, truncate it as needed and use it as an index vector:
x = {'ae' ; 'be' ; 'ce' ; 'de' ; 'ee' ; 'fe'}
N = 3;
n = numel(x);
A = gallery('circul',n:-1:1)
B = fliplr( A(1:n-N+1,n-N+1:end) )
result = x(B)
or a little shorter:
A = fliplr( gallery('circul',n:-1:1) )
result = x( A(1:n-N+1,1:n-N) )
or another option using the hankel-Matrix:
A = hankel(1:n,1:N)
result = x( A(1:n-N+1,:) )
gives:
result =
'ae' 'be' 'ce'
'be' 'ce' 'de'
'ce' 'de' 'ee'
'de' 'ee' 'fe'

Replace strings with integer IDs in a Cell - Matlab

I have a cell that has string IDs. I need to replace them with integer IDs so that the cell can be transformed into a matrix. I especially need this to be a vectorized operation as the celldata is huge.
celldata = { 'AAPL' [0.1] ; 'GOOG' [0.643] ; 'IBM' [0.435] ; 'MMM' [0.34] ; 'AAPL' [0.12] ; 'GOOG' [1.5] ; 'IBM' [0.75] ; 'AAPL' [0.56] ; 'GOOG' [0.68] ; 'IBM' [0.97] ; };
I designed a sequential intID:
intIDs = {'AAPL' [1] ; 'GOOG' [2] ; 'IBM' [3] ; 'MMM' [4]};
intIDs contain ALL IDs that are possible in celldata. Also, celldata has IDs in sequential order and grouper together by dates. The date column is not shown here.
Desired result:
celldata = {[1] [0.1] ; [2] [0.643] ; [3] [0.435] ; [4] [0.34] ; [1] [0.12] ; [2] [1.5] ; [3] [0.75] ; [1] [0.56] ; [2] [0.68] ; [3] [0.97] ;};
Thanks!
You can use the ismember function and logical indexing to achieve what you want.
[~,indx]=ismember(celldata(:,1),intIDs(:,1));
celldata(:,1)=intIDs(indx,2)
celldata =
[1] [0.1000]
[2] [0.6430]
[3] [0.4350]
[4] [0.3400]
[1] [0.1200]
[2] [1.5000]
[3] [0.7500]
[1] [0.5600]
[2] [0.6800]
[3] [0.9700]