Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql query insert using equals signs

Tags:

sql

php

mysql

This may be an easy questions but i am wondering if an "insert" sql statement can be writen with equals signs.

Example: Right now my sql looks like this and works fine:

$query = "INSERT INTO people (
        id, 
        name, 
) VALUES (
        {$id},
        '{$name}',

)

So i was wondering if i can write the sql statement like this or something similar to this using = signs:

 $query = "INSERT INTO people 
        id = {$id},
        name = '{$site_url}',

Thank you for any help. I am just looking for an easier way to write this code especially when i have a lot of form fields. Thanks.

like image 258
user982853 Avatar asked Jan 04 '12 22:01

user982853


People also ask

Can we use where condition in insert query?

Insert query doesn't support where keyword* Conditions apply because you can use where condition for sub-select statements. You can perform complicated inserts using sub-selects.

What does the equal sign mean in SQL?

In SQL, = means is equal to . (at least here; in update statements it can be an assignment Update x FROM y ... SET x.a = y.b, ... ) – wildplasser. Feb 2 at 21:06. In predicates = evaluates to true when both sides are known/bound/non-null and have the same value, as in your example above.

What Is syntax for insert?

There are two basic syntax of INSERT INTO statement is as follows: INSERT INTO TABLE_NAME (column1, column2, column3,... columnN)] VALUES (value1, value2, value3,... valueN);


1 Answers

Yes.

You have to use SET

$query = "INSERT INTO people 
    SET id = {$id},
    name = '{$site_url}'";
like image 98
Johnny Craig Avatar answered Oct 14 '22 11:10

Johnny Craig