I would like to write this MYSQL query
SET @val := 0;
SELECT `my_table`.* FROM `my_table` HAVING (@val := @val + 1) > 0;
inside PHP
code that using database extention PDO
!
I've seen that mysqli
have mysqli_multi_query()
but i do not know does PDO
support multi queries by some how?!
I've try this
<?PHP
// i'm connected to db
$sql = "SET @val := 0;";
$sql .= "SELECT `my_table`.* FROM `my_table` HAVING (@val := @val + 1) > 0;";
?>
<table>
<tr>
<th>id</th>
<th>name</th>
</tr>
<?PHP foreach($db->query($sql) as $row){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
</tr>
<?php } ?>
</table>
But did not works!
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error in \path\test.php:25 Stack trace: #0 {main} thrown in \path\test.php on line 25
and line 25 is : <?PHP foreach($db->query($sql) as $row){ ?>
looks like it not passing the query! so any idea