fetchall

Php Prepared Statements Turn Emulation Off

霸气de小男生 提交于 2019-11-27 02:23:22
问题 Are there any side effects to turning off emulation when using prepared statements with pdo? I'm using a select * and limiting the results which needs to be handled as an int and not a string. I can do one of two things. $conn->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ); Or to bind these variables explicitly with param type: $stm = $pdo->prepare('SELECT * FROM table LIMIT ?, ?'); $stm->bindParam(1, $limit_from,PDO::PARAM_INT); $stm->bindParam(2, $per_page,PDO::PARAM_INT); $stm->execute

PDO looping throug and printing fetchAll

穿精又带淫゛_ 提交于 2019-11-27 01:29:27
问题 I'm having trouble getting my data from fetchAll to print selectively. In normal mysql I do it this way: $rs = mysql_query($sql); while ($row = mysql_fetch_array($rs)){ $id = $row['id']; $n = $row['n']; $k = $row['k']; } In PDO, I'm having trouble. I bound the params, then I'm saving the fetched data into $rs like above, with the purpose of looping through it the same way.. $sth->execute(); $rs = $query->fetchAll(); Now comes the trouble part. What do I do PDO-wise to get something matching