List:General Discussion« Previous MessageNext Message »
From:Steven Staples Date:February 22 2012 3:47pm
Subject:MySQL Session Variables with PHP
View as plain text  
Good [insert time of day here] all!

I am trying to reorder my auto-inc field in my database, and I have
successfully done it with my "front end" that I use (SQLYog) with the
following code:

SET @var_name = 0; 
UPDATE `my_database`.`my_table` SET `id` = (@var_name := @var_name +1);


Now, when I try this within PHP... I can't get it to work at all.  I assume
that the SET is the issue, but I am not 100% sure.

I use the PEAR MDB2 class, and I have tried it in 1 statement, but it
failed, and I tried it with 2 statements, it didn't puke on it, but it
didn't work either.

<?php
	# db connection is already set up #
	echo $db->exec('SET @var_name = 0;')
	echo '<br />';
	echo $db->exec('UPDATE `my_database`.`my_table` SET `id` =
(@var_name:= @ var_name +1);');
	exit;
?>

Does anyone know how I can do this within PHP?  Worst case scenario, is that
I just write a php shell() command instead, but I would rather avoid that if
at all possible.

Thanks in advance!

Steven Staples


Thread
MySQL Session Variables with PHPSteven Staples22 Feb
  • Re: MySQL Session Variables with PHPPeter Brawley22 Feb
    • RE: MySQL Session Variables with PHPSteven Staples22 Feb
      • Re: MySQL Session Variables with PHPJohan De Meersman22 Feb