Fetch mode

ADOdb propose ces modes de récupération :

  • ADODB_FETCH_DEFAULT (par défaut et équivalant à ADODB_FETCH_BOTH)
  • ADODB_FETCH_NUM
  • ADODB_FETCH_ASSOC
  • ADODB_FETCH_BOTH

On peut définir le mode de fetch avec :

global $ADODB_FETCH_MODE;
   $ADODB_FETCH_MODE = ADODB_FETCH_NUM;

ou plus proprement pour chaque connexion avec :

$dbconn = NewADOConnection( $dbtype );
   $dbconn->SetFetchMode(ADODB_FETCH_ASSOC);

ADODB Manual : ADONewConnection($driver) function. NewADOConnection($driver) is an alternative name for the same function.

Nom des champs en Lower Case

// Get database parameters
 
    $dbconn = ADONewConnection($dbtype);
    $dbh = $dbconn->Connect($dbhost, $dbuname, $dbpass, $dbname);	
    if (!$dbh) {
        die($dbconn->ErrorMsg());
 
	$query = "SELECT idUtilisateur AS idUser, groupe FROM Utilisateur WHERE 1";
	$result = $dbconn->Execute($query);
	if($dbconn->ErrorNo() != 0) { die($dbconn->ErrorMsg(); }
 
	var_dump($result);
 
	$i=0;
	while(!$result->EOF) {
//		$row = $result->GetRowAssoc(0);
		$row = $result->fields;
print_r($row);
		$result->MoveNext();
	}

Sans modifier le fetch mode (par défaut et équivalant à ADODB_FETCH_BOTH)

$row = $result->fields;

Array ( [0] => 36 [idUser] => 36 [1] => Admin [groupe] => Admin )

$row = $result->GetRowAssoc(false);

Array ( [iduser] => 36 [groupe] => Admin )

Deprecated GetRowAssoc : Note: do not use GetRowAssoc() with $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC. Because they have the same functionality, they will interfere with each other.

En plus d'être obsolète, on constate que cette fonction met en minuscule ou majuscule les champs demandé, impossible donc d'obtenir un un field simultanément composé de minuscules et majuscules.

ADODB LDAP, changement du base_dn pour la recherche

L'équivalent d'une recherche LDAP en spécifiant le DN (base_dn) se fait en changeant la base de données avec $connADO->SelectDB($baseDn);

/* Make sure to set this BEFORE calling Connect() */
				$LDAP_CONNECT_OPTIONS = array(
												array ("OPTION_NAME"=>LDAP_OPT_DEREF, "OPTION_VALUE"=>2),
												array ("OPTION_NAME"=>LDAP_OPT_SIZELIMIT,"OPTION_VALUE"=>100),
												array ("OPTION_NAME"=>LDAP_OPT_TIMELIMIT,"OPTION_VALUE"=>30),
												array ("OPTION_NAME"=>LDAP_OPT_PROTOCOL_VERSION,"OPTION_VALUE"=>3),
												array ("OPTION_NAME"=>LDAP_OPT_ERROR_NUMBER,"OPTION_VALUE"=>13),
												array ("OPTION_NAME"=>LDAP_OPT_REFERRALS,"OPTION_VALUE"=>FALSE),
												array ("OPTION_NAME"=>LDAP_OPT_RESTART,"OPTION_VALUE"=>FALSE)
											);
 
				$host = 'ldap.baylor.edu';
				$ldapbase = 'ou=People,o=Baylor University,c=US';
 
				$this->ldap = NewADOConnection( 'ldap' );
//				$this->ldap->LDAP_CONNECT_OPTIONS = $LDAP_CONNECT_OPTIONS;
				$this->ldap->SetFetchMode(ADODB_FETCH_ASSOC);
//				$ldap->Connect( $host, $user_name='', $password='', $ldapbase );
				$this->ldap->Connect( $host, 'cn=admin,dc=tata', 'password', $ldapbase );
//				var_dump($this->ldap);
				$this->ldap->SelectDB('ou=toto,dc=tata');

Ressources