Conversione funzione php

XinYiMan

Nuovo Utente
26 Mar 2010
5
0
0
Ragazzi ho questa funzione qui

PHP:
	function fetch_pairs($mysqli,$query){
		if (!($res = $mysqli->query($query)))return FALSE;
		$rows = array();	
		while ($row = $res->fetch_assoc()) {
			$first = true;
			$key = $value = null;
			foreach ($row as $val) {
				if ($first) { $key = $val; $first = false; }
				else { $value = $val; break; } 
			}
			$rows[$key] = $value;
		}
		return $rows;
	}

e vorrei che al posto delle funzioni native per lavorare con php usasse le PDO, ho provato così, ma non funziona, cosa non mi torna?

PHP:
	function fetch_pairs($connection,$query){
		$sth=$connection->prepare($query);
		$righe=$sth->execute();		
		$res=$sth->fetchAll(PDO::FETCH_ASSOC);
		
		$rows=$res; //DA CAMBIARE		

		return $rows;
	}
 
Ultima modifica di un moderatore:

Discussioni simili