Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2003, 01:54 PM
Authorized User
 
Join Date: Sep 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert null value in MySql?

Looked in both PHP reference and MySQL reference, and don't see the syntax to use to set a database field to the value of NULL, using the SET field=value form of the SQL syntax.

Have:
$var = ?????;
...
INSERT INTO ... ... SET Fieldname='$var' ...

What do I set ????? to in order to make that field null?

thanks.
don
 
Old November 28th, 2003, 10:38 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

In MySQL null can have a special meaning, like triggering an auto-incremented field or resetting a timestamp. It doesn't accept a null value for a field unless you specifically tell it to.

Here is a table with the creation of a field that does accept null values:

CREATE TABLE `null_test` (
`null_field` TEXT
);

INSERT INTO `null_test` VALUES(null);

Just inserts an empty row into that table.

UPDATE `null_test` SET `null_field` = null;

Updates `null_field` in all rows in the table to null.

CREATE TABLE `null_test` (
`null_field` TEXT NOT NULL
);

Creates the same table but does not allow null values!
MySQL comes back with the error:
#1048 - Column 'null_field' cannot be null

So having said all that, in answer to your question:
Quote:
quote:
 Looked in both PHP reference and MySQL reference, and don't see the syntax to use to set a database field to the value of NULL, using the SET field=value form of the SQL syntax.
its `field_name` = null

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old November 28th, 2003, 11:55 PM
Authorized User
 
Join Date: Sep 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Rich. I had tried setting field_name = 'null', but hadn't tried it without the quotes, which makes sense considering that null is a special value, and not just a string that says "null".
-don





Similar Threads
Thread Thread Starter Forum Replies Last Post
Row is null after formview insert?? stapes ASP.NET 2.0 Basics 1 June 27th, 2008 10:19 AM
INSERT with MySQL sethtrain BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 August 1st, 2006 06:38 AM
BULK INSERT NULL(s) nathansevugan SQL Server 2000 2 November 29th, 2005 01:11 AM
insert null value into database akibaMaila VB.NET 2002/2003 Basics 1 August 15th, 2005 05:44 PM
Stored Procedure Insert Null Value harpua SQL Server ASP 2 March 5th, 2005 10:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.