Bpicks
Bpicks

Reputation: 31

How to do PHP insert using SQL 'Default' keyword for auto incremented primary key

Hi, i'm trying to do a PHP insert using PDO:

$sqlStr = "INSERT INTO agents VALUES (:id,:sport, :firmName, :agentLastName, :agentFirsttName, :address1, :address2, :suite, :city, :stateProv, :zipcode, :country, :phone, :fax, :email, :website, :comment, :lastUpdated)";

I want to bind the MySQL 'Default' keyword to my id because my id is auto incremented. But, 'Default' is already a keyword in PHP.

Is there any way I can accomplish this?

Thanks

Upvotes: 0

Views: 103

Answers (1)

Dormilich
Dormilich

Reputation: 927

The quick fix: pass NULL for the ID.

The good fix: list all fields in the statement that should receive a value and omit the id field. (This way you can also use the auto update capabilities of a TIMESTAMP column)

Upvotes: 1

Related Questions