عرض ادب
یک سوال داشتم
وقتی کدهای این جلسه رو باهم اجرا میکنم به خطا برمیخورم اما زمانی که بعضی از query هارو کامنت میکنم مشکلی در خروجی وحود نداره. میخواستم بدونم دلیل این خطا چی هست؟
<?php include_once '01-connection.php'; $id = 137; # using fetch_assoc $sqlQuery = "SELECT * FROM people7 where id > $id"; $query = $conn->query($sqlQuery); //print_r($result); echo ""; while ($row = $query->fetch_assoc()) { echo ""; foreach ($row as $key => $value){ echo "$value"; } } # using prepare and bind_result() $sqlQuery = "SELECT count(*) as count from people7"; $stmt = $conn->prepare($sqlQuery); $stmt->execute(); echo $stmt->bind_result($count); $stmt->fetch(); echo $count."
"; // prepare stmt practice #2 $sqlQuery = "SELECT avg(age) as average_age from people7"; $stmt = $conn->prepare($sqlQuery); $stmt->execute(); $stmt->bind_result($average_age); $stmt->fetch(); echo "people average age is $average_age "; # prepare bind_result with multi data fetched $sqlQuery = "SELECT id,fullname,age from people7 where id between 50 AND 100"; $stmt = $conn->prepare($sqlQuery); $stmt->execute(); $stmt->bind_result($id,$fullname,$age); $stmt->fetch(); while($stmt->fetch()){ echo "
".$id."=>".$fullname. ":".$age. "
"; } $sqlQuery = "SELECT * FROM people1"; $stmt = $conn->prepare($sqlQuery); $stmt->execute(); $stmt->store_result(); var_dump($stmt); ?>
158 Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in F:\\Xampp\\htdocs\\7Learn.php\\mysql\\06-select.php:40 Stack trace: #0 F:\\Xampp\\htdocs\\7Learn.php\\mysql\\06-select.php(40): mysqli->prepare('SELECT avg(age)...') #1 {main} thrown in F:\\Xampp\\htdocs\\7Learn.php\\mysql\\06-select.php on line 40 138 zahra864 46 m 139 zahra864 46 m 140 zahra864 46 f 141 zahra864 46 f 142 zahra864 46 f 143 zahra864 46 m 144 zahra864 46 f 145 zahra864 46 m 146 zahra864 46 f 147 zahra864 46 f