Skip to content

Instantly share code, notes, and snippets.

@dcsg
Created March 29, 2012 22:52
Show Gist options
  • Save dcsg/2244589 to your computer and use it in GitHub Desktop.
Save dcsg/2244589 to your computer and use it in GitHub Desktop.
Creating a mysql counter variable
<?php
// I am using Symfony2 with it!
// Getting the connection
$conn = $this->getDoctrine()->getConnection();
// Sets the SQL counter variable
$conn->exec("SET @I := 0");
//Retrieve the data
$result = $conn->fetchAll("SELECT @I := @I+1 AS counter, others_columns FROM table");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment