php - Return PDO data -
hi guys have program built using mysql_* , trying convert pdo security , depreciative reasons
so have load of mysql_* functions setup like
return select_from_where('users', '*', "username = '$username' , password = '$pass'", "limit 1");
which have converted pdo
return $conn -> query("select * users username = '$username' , password = '$pass' limit 1");
however program not feed right result, i'm not sure if returning data
my question is, have set pdo response variable can use, or possible have return values can use in program using similar method above?
i have included global $conn each function query i'm sure connecting should, not feeding result intended..
does have quick fix issue program done , pending release :d
thanks in advance
luke
** edit line *
$sql = ("select * users username = '$username' , password = '$pass' limit 1"); $stm = $conn->prepare($sql); $stm->execute(array($username,$pass)); $user = $stm->fetch(); echo $user['username'];
first, see no point in having function select_from_where
you save nothing - moved words "select, , where" query function name, yet made function extremely limited - say, no joins or stuff.
second, pdo::query()
function shouldn't used anyway - it doesn't support prepared statements.
so, code have be
global $conn; $sql = "select * users username = ? , password = ? limit 1"; $stm = $conn->prepare($sql); $stm->execute(array($username,$pass)); return $stm->fetch();
you have configure php , pdo in order able see every error occurred.
Comments
Post a Comment