sizeof($array)) $max = sizeof($array); else $max = $probe; for ($j=0;$j < $max; $j++) { $row = $array[$j]; if (!$row) break; $i = -1; foreach($row as $v) { $i += 1; if (isset($types[$i]) && $types[$i]=='C') continue; //print " ($i ".$types[$i]. "$v) "; $v = trim($v); if (!preg_match('/^[+-]{0,1}[0-9\.]+$/',$v)) { $types[$i] = 'C'; // once C, always C continue; } if ($j == 0) { // If empty string, we presume is character // test for integer for 1st row only // after that it is up to testing other rows to prove // that it is not an integer if (strlen($v) == 0) $types[$i] = 'C'; if (strpos($v,'.') !== false) $types[$i] = 'N'; else $types[$i] = 'I'; continue; } if (strpos($v,'.') !== false) $types[$i] = 'N'; } } } function adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs) { $oldX = sizeof(reset($arr)); $oldY = sizeof($arr); if ($hdr) { $startx = 1; $hdr = array('Fields'); for ($y = 0; $y < $oldY; $y++) { $hdr[] = $arr[$y][0]; } } else $startx = 0; for ($x = $startx; $x < $oldX; $x++) { if ($fobjs) { $o = $fobjs[$x]; $newarr[] = array($o->name); } else $newarr[] = array(); for ($y = 0; $y < $oldY; $y++) { $newarr[$x-$startx][] = $arr[$y][$x]; } } } // Force key to upper. // See also http://www.php.net/manual/en/function.array-change-key-case.php function _array_change_key_case($an_array) { if (is_array($an_array)) { $new_array = array(); foreach($an_array as $key=>$value) $new_array[strtoupper($key)] = $value; return $new_array; } return $an_array; } function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc) { if (count($fieldArray) == 0) return 0; $first = true; $uSet = ''; if (!is_array($keyCol)) { $keyCol = array($keyCol); } foreach($fieldArray as $k => $v) { if ($v === null) { $v = 'NULL'; $fieldArray[$k] = $v; } else if ($autoQuote && /*!is_numeric($v) /*and strncmp($v,"'",1) !== 0 -- sql injection risk*/ strcasecmp($v,$zthis->null2null)!=0) { $v = $zthis->qstr($v); $fieldArray[$k] = $v; } if (in_array($k,$keyCol)) continue; // skip UPDATE if is key if ($first) { $first = false; $uSet = "$k=$v"; } else $uSet .= ",$k=$v"; } $where = false; foreach ($keyCol as $v) { if (isset($fieldArray[$v])) { if ($where) $where .= ' and '.$v.'='.$fieldArray[$v]; else $where = $v.'='.$fieldArray[$v]; } } if ($uSet && $where) { $update = "UPDATE $table SET $uSet WHERE $where"; $rs = $zthis->Execute($update); if ($rs) { if ($zthis->poorAffectedRows) { /* The Select count(*) wipes out any errors that the update would have returned. http://phplens.com/lens/lensforum/msgs.php?id=5696 */ if ($zthis->ErrorNo()<>0) return 0; # affected_rows == 0 if update field values identical to old values # for mysql - which is silly. $cnt = $zthis->GetOne("select count(*) from $table where $where"); if ($cnt > 0) return 1; // record already exists } else { if (($zthis->Affected_Rows()>0)) return 1; } } else return 0; } // print "

Error=".$this->ErrorNo().'

'; $first = true; foreach($fieldArray as $k => $v) { if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col if ($first) { $first = false; $iCols = "$k"; $iVals = "$v"; } else { $iCols .= ",$k"; $iVals .= ",$v"; } } $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)"; $rs = $zthis->Execute($insert); return ($rs) ? 2 : 0; } function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { global $ADODB_FETCH_MODE; $s = _adodb_getmenu_select($name, $defstr, $blank1stItem, $multiple, $size, $selectAttr); $hasvalue = $zthis->FieldCount() > 1; if (!$hasvalue) { $compareFields0 = true; } $value = ''; while(!$zthis->EOF) { $zval = rtrim(reset($zthis->fields)); if ($blank1stItem && $zval == "") { $zthis->MoveNext(); continue; } if ($hasvalue) { if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) { // Get 2nd field's value regardless of its name $zval2 = current(array_slice($zthis->fields, 1, 1)); } else { // With NUM or BOTH fetch modes, we have a numeric index $zval2 = $zthis->fields[1]; } $zval2 = trim($zval2); $value = 'value="' . htmlspecialchars($zval2) . '"'; } $s .= _adodb_getmenu_option($defstr, $compareFields0 ? $zval : $zval2, $value, $zval); $zthis->MoveNext(); } // while return $s ."\n\n"; } function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, $size=0, $selectAttr='',$compareFields0=true) { global $ADODB_FETCH_MODE; $s = _adodb_getmenu_select($name, $defstr, $blank1stItem, $multiple, $size, $selectAttr); $hasvalue = $zthis->FieldCount() > 1; $hasgroup = $zthis->FieldCount() > 2; if (!$hasvalue) { $compareFields0 = true; } $value = ''; $optgroup = null; $firstgroup = true; while(!$zthis->EOF) { $zval = rtrim(reset($zthis->fields)); $group = ''; if ($blank1stItem && $zval=="") { $zthis->MoveNext(); continue; } if ($hasvalue) { if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) { // Get 2nd field's value regardless of its name $fields = array_slice($zthis->fields, 1); $zval2 = current($fields); if ($hasgroup) { $group = trim(next($fields)); } } else { // With NUM or BOTH fetch modes, we have a numeric index $zval2 = $zthis->fields[1]; if ($hasgroup) { $group = trim($zthis->fields[2]); } } $zval2 = trim($zval2); $value = "value='".htmlspecialchars($zval2)."'"; } if ($optgroup != $group) { $optgroup = $group; if ($firstgroup) { $firstgroup = false; } else { $s .="\n"; } $s .="\n"; } $s .= _adodb_getmenu_option($defstr, $compareFields0 ? $zval : $zval2, $value, $zval); $zthis->MoveNext(); } // while // closing last optgroup if($optgroup != null) { $s .= "\n"; } return $s ."\n\n"; } /** * Generate the opening SELECT tag for getmenu functions. * * ADOdb internal function, used by _adodb_getmenu() and _adodb_getmenu_gp(). * * @param string $name * @param string $defstr * @param bool $blank1stItem * @param bool $multiple * @param int $size * @param string $selectAttr * * @return string HTML */ function _adodb_getmenu_select($name, $defstr = '', $blank1stItem = true, $multiple = false, $size = 0, $selectAttr = '') { if ($multiple || is_array($defstr)) { if ($size == 0 ) { $size = 5; } $attr = ' multiple size="' . $size . '"'; if (!strpos($name,'[]')) { $name .= '[]'; } } elseif ($size) { $attr = ' size="' . $size . '"'; } else { $attr = ''; } $html = '