1
$sqlcount1 ="SET uid = -1 UPDATE `agent_normal` SET `uid` = @a:=@a+1";
$result = mysqli_query($conn,$sqlcount1);

how to write this query in core php?

This query works in mysql but not in core php.

Here i want to update a single row of table and value should start from 0 and then should increment by 1.

Mike
  • 23,542
  • 14
  • 76
  • 87
Mohsin
  • 199
  • 5
  • 19
  • The code above **is** core PHP. Please clarify exactly what it is you're trying to do and what problems you're encountering. – Mike Apr 14 '18 at 05:18
  • Possible duplicate of [How to renumber primary index](https://stackoverflow.com/questions/2643371/how-to-renumber-primary-index) – Nick Apr 14 '18 at 05:24
  • @Mike this query doesnt work in core php but works in phpmyadmin. – Mohsin Apr 14 '18 at 05:33
  • @Nick yes both the queries are same but how do i use it in core php??? – Mohsin Apr 14 '18 at 05:34

1 Answers1

2

There are a couple of problems. Firstly, if you look at this answer you'll see you have an incorrect variable name and missing semicolon. The query should be :

$sqlcount1 ="SET @a = -1; UPDATE `agent_normal` SET `uid` = @a:=@a+1";

Secondly, to use two queries in one call you need to use mysqli_multi_query.

$result = mysqli_multi_query($conn,$sqlcount1);
Nick
  • 138,499
  • 22
  • 57
  • 95