php - MySQL query to PDO -
i've been suggested migrate deprecated mysql mysqli or pdo, got around it'll project without wasting time. i've been reading lot on great articles , websites, i'd best suggestion on how fetch array pdo, can while loop dislike it, how convert current code pdo.
public function user_details($_id){ $_id = mysql_real_escape_string($_id); $query="select _id,_ipassword,_iemail,_inickname,_iusername,_iprofilepicture,_ifriendcount users _id='$_id' , _istatus='1'"; $result = mysql_query($query) or die(mysql_error()); $data = mysql_fetch_array($result) or die(mysql_error()); return $data; }
i able while loop said, that's not i'm interested in unless it's better option.
pdo :
$sql = "select _id,_ipassword,_iemail,_inickname,_iusername,_iprofilepicture,_ifriendcount users _istatus='1'"; foreach ($db->query($sql) $row){ print $row['_id'] .' - '. $row['_iusername'] . '<br />'; }
it wise study how pdo different old methods instead of trying old way new tools. 1 of things pdo offers create prepared statements, can execute, , fetch in various ways. think fetchall method looking for.
Comments
Post a Comment