Skip to content
Advertisement

Update Multiple columns with no effect

I am developing an API’s, in my project we are using dynamic databases so for that one i am connecting databases by using mysqli it’s working fine i can able to do CRUD operations also on Database but if i try to update multiple columns at that time changes are not reflected in Database did i miss anything can anyone please help me ?

$childConnection=  new mysqli(env('DB_HOST', '127.0.0.1'), env('DB_USERNAME', 'test'), env('DB_PASSWORD', ''), $item->dbname,env('DB_PORT', '3306'),env('DB_SOCKET', ''));
$uname="test";
$uid="10";
$childConnection->query("UPDATE users SET name={$uname} WHERE id={$uid}"); // this query is working fine.

 $t_now = Carbon::now();
 $t_sessionStarted = CarbonCarbon::parse($userData['log_time']);
 $r_time= $t_sessionStarted->diffForHumans($t_now, ['parts' => 3, 'syntax' => CarbonInterface::DIFF_ABSOLUTE]); //output is "2hours 50minutes"
$childConnection->query("UPDATE users SET ltime={$r_time} WHERE id={$uid}"); //This is not working

Desc users :- ltime is VARCHAR(300)

Advertisement

Answer

name={$uname} should be name='{$uname}' since it is a string

same for SET ltime={$r_time} should be SET ltime='{$r_time}'

also VARCHAR cannot be > 255

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement