473,392 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,392 software developers and data experts.

Question about Null values

A section of the documentation for the isSet() function states:

Also note that a NULL byte ("\0") is not equivalent to the PHP NULL
constant.

Where would you encounter a NULL byte? Is a null byte what is returned
from a field in a database?

Josh
Jul 17 '05 #1
9 12183
Joshua Ruppert:
A section of the documentation for the isSet() function states:

Also note that a NULL byte ("\0") is not equivalent to the PHP NULL
constant.

Where would you encounter a NULL byte? Is a null byte what is returned
from a field in a database?


It's typically used in C to mark the end of a string. As you might know the
programmer is responsible for managing memory in C. This means that if you
want to store a string coming from the user using C, you will have to set
aside some buffer space, say 4096B. If the user sends a string of only 67B
the \0 byte is used in this buffer to mark the end of the string.

Luckily it's not anything you really have to worry about in PHP.

André Nęss
Jul 17 '05 #2
> It's typically used in C to mark the end of a string. As you might know the
programmer is responsible for managing memory in C. This means that if you
want to store a string coming from the user using C, you will have to set
aside some buffer space, say 4096B. If the user sends a string of only 67B
the \0 byte is used in this buffer to mark the end of the string.

Luckily it's not anything you really have to worry about in PHP.


right - in php, the NULL Character is a Character like every other (besindes some functions don't work right with it)

But nothing should give you such a Character (besindes the evil evil user)
--
mfg Christian (Chronial "at" web.de)

--
Composed with Newz Crawler 1.5 http://www.newzcrawler.com/
Jul 17 '05 #3
On Tue, 16 Dec 2003 12:03:31 +0100, "Christian Fersch"
<Fr********@web.de> wrote:
It's typically used in C to mark the end of a string. As you might know the
programmer is responsible for managing memory in C. This means that if you
want to store a string coming from the user using C, you will have to set
aside some buffer space, say 4096B. If the user sends a string of only 67B
the \0 byte is used in this buffer to mark the end of the string.

Luckily it's not anything you really have to worry about in PHP.


right - in php, the NULL Character is a Character like every other (besindes some functions don't work right with it)

But nothing should give you such a Character (besindes the evil evil user)


If you were to retrieve a BLOB field from a database, it could contain
"null" (\0) characters.

In database terms, "NULL" means "no data". The "null character" *is*
data - a byte with a value of zero.

--
David ( @priz.co.uk )
The Internet Prisoner Database: http://www.priz.co.uk/ipdb/
The Tarbrax Chronicle: http://www.tarbraxchronicle.com/
Jul 17 '05 #4
On Tue, 16 Dec 2003 11:18:55 +0000, David Mackenzie hath writ:
....... The "null character" *is* data - a byte with a value of zero.


More properly: "...a byte with a value of" *nothing* .
Not zero , not alpha , not numeric , not feet , not inches...
At best it is a placeholder -- where _something_ could be -- but,
at the present time, there is *nothing* there.

As a thing meaning *nothing*, in C-like constructs it is usually
used the show the end of *something* .

Jonesy
--
| Marvin L Jones | jonz | W3DHJ | OS/2
| Gunnison, Colorado | @ | Jonesy | linux __
| 7,703' -- 2,345m | config.com | DM68mn SK
Jul 17 '05 #5
On 16 Dec 2003 16:12:12 GMT, Allodoxaphobia <bi********@config.com> wrote:
On Tue, 16 Dec 2003 11:18:55 +0000, David Mackenzie hath writ:
....... The "null character" *is* data - a byte with a value of zero.
More properly: "...a byte with a value of" *nothing* .
Not zero , not alpha , not numeric , not feet , not inches...
At best it is a placeholder -- where _something_ could be -- but,
at the present time, there is *nothing* there.


Well, a NUL character is CHR(0) and is a one-byte zero, it is very much
something. You seem to be almost describing an SQL database NULL, which
represents 'unknown'.
As a thing meaning *nothing*, in C-like constructs it is usually
used the show the end of *something* .


Character strings are terminated in C by a NUL (chr(0)) character. It is
definitely 'something' itself, since you have to allocate space for it. PHP's a
higher-level language so you don't have to worry about NUL terminators. And you
can have NUL bytes in PHP 'string' variables, as they're actually
'binary-safe'.

<pre>
<?php
$x = chr(0).chr(0).chr(0).chr(0).'x';
var_dump($x);
?>
</pre>

string(5) "x"

(Note the length!)

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #6
So would a null byte be basically an empty string as opposed to an
unknown value?

Josh

Andy Hassall wrote:
On 16 Dec 2003 16:12:12 GMT, Allodoxaphobia <bi********@config.com> wrote:

On Tue, 16 Dec 2003 11:18:55 +0000, David Mackenzie hath writ:

....... The "null character" *is* data - a byte with a value of zero.


More properly: "...a byte with a value of" *nothing* .
Not zero , not alpha , not numeric , not feet , not inches...
At best it is a placeholder -- where _something_ could be -- but,
at the present time, there is *nothing* there.

Well, a NUL character is CHR(0) and is a one-byte zero, it is very much
something. You seem to be almost describing an SQL database NULL, which
represents 'unknown'.

As a thing meaning *nothing*, in C-like constructs it is usually
used the show the end of *something* .

Character strings are terminated in C by a NUL (chr(0)) character. It is
definitely 'something' itself, since you have to allocate space for it. PHP's a
higher-level language so you don't have to worry about NUL terminators. And you
can have NUL bytes in PHP 'string' variables, as they're actually
'binary-safe'.

<pre>
<?php
$x = chr(0).chr(0).chr(0).chr(0).'x';
var_dump($x);
?>
</pre>

string(5) "x"

(Note the length!)

Jul 17 '05 #7
On Tue, 16 Dec 2003 23:04:36 GMT, Joshua Ruppert
<no************@rochester.rr.com> wrote:
So would a null byte be basically an empty string as opposed to an
unknown value?


In which language?

C: Yes, a single NUL character is the representation of a zero-length string.
PHP: No, it'd be a 1-character string consisting of a chr(0).

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #8
Another Newbie here...

doing a small order tracking app to learn PHP, MySQL, etc...

With regard to null values, I have a customer entry form in html.Some
fields are optional. I send data to MySQL via a POST method. When I
try to query the database later (via a form as well) and use "IS
NULL", for example:

select c.lname, c.fname
from Customer c
where c.company_name is null

....I get no results. I have to query the db with something like

select c.lname, c.fname
from Customer c
where (c.company_name='')

What am I doing wrong? There do not seem to be any null values in my
db, only empty values ('').

I suspect it has to do with the addslashes() function applied to the
post variables on the customer insert page. Must I NOT addslashes() if
the POST field has been skipped by the user?

Thanks!

On Tue, 16 Dec 2003 23:25:55 +0000, Andy Hassall <an**@andyh.co.uk>
wrote:
On Tue, 16 Dec 2003 23:04:36 GMT, Joshua Ruppert
<no************@rochester.rr.com> wrote:
So would a null byte be basically an empty string as opposed to an
unknown value?


In which language?

C: Yes, a single NUL character is the representation of a zero-length string.
PHP: No, it'd be a 1-character string consisting of a chr(0).


Jul 17 '05 #9
Adam M. Johnson <ad***@althealth.org> wrote:
With regard to null values, I have a customer entry form in html.Some
fields are optional. I send data to MySQL via a POST method. When I
try to query the database later (via a form as well) and use "IS
NULL", for example:

select c.lname, c.fname
from Customer c
where c.company_name is null

...I get no results. I have to query the db with something like

select c.lname, c.fname
from Customer c
where (c.company_name='')

What am I doing wrong? There do not seem to be any null values in my
db, only empty values ('').

I suspect it has to do with the addslashes() function applied to the
post variables on the customer insert page. Must I NOT addslashes() if
the POST field has been skipped by the user?


perhaps you can test your POST variables before inserting them in the
database, i.e.

if (empty($_POST['myvar'])) {
$myvar = 'NULL';
}
else {
// note the surrounding quotes
$myvar = "'".mysql_escape_string(stripslashes($_POST['myvar']))."'";
}

mysql_query("UPDATE table SET field=".$myvar);
(or INSERT, whatever you are using...)

if they are empty, NULL will be inserted in the database; if not,
stripslashes strips \ from the variable the form transmits, and
mysql_escape_string escapes special characters when passing the sql query
statement.
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Spark | last post by:
Hi, Situation: Need a query to return number of ticket records by month of open in a log table where the ticket open record is older than 24 hours then the ticket pending or ticket closed...
19
by: John Pifer | last post by:
I am not good at SQL - hence here goes Consider this scenario of 2 tables X and Y with a many to many relationship Table X (name,weightage) X1 2 X2 1 X3 5 X4 1
1
by: Diego Buendia | last post by:
I'm facing the next problem: I have a table with two columns (among others) modeling category and subcategory data for each row. I need to summarize info on this two columns, but with the next...
2
by: Karsten Hilbert | last post by:
Dear all, for some reason I just cannot get my brain wrapped around the required syntax for the following. I think I need to either use a join or subselect(s): Situation: ---------- I have...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
7
by: JJ | last post by:
How do I set one field to have the updated timestamp, and another to have the created timestamp? I want to do this directly from code generated from DB Designer if possible?! JJ
0
by: =?Utf-8?B?Uml6d2Fu?= | last post by:
I have these tables: create table cd_language_saaa ( saaapk int not null PRIMARY KEY, code varchar(50) not null ) create table cd_calendar_saaj (
5
by: Michael_Burgess | last post by:
Hi there, I'm fairly new to database design, having only really worked with existing tables etc in the past. Simple question this really........... In a users table, is it wise to have a...
6
by: BD | last post by:
Hi, all. I'm trying to understand a certain RI question. I have 3 tables. TABLE_A has a PK of A_1. TABLE_B has a PK of B_1,A_1 (it's a composite key, with the second field being a FK to...
22
by: Bill Reid | last post by:
I just noticed that my "improved" version of sscanf() doesn't assign floating point numbers properly if the variable assigned to is declared as a "float" rather than a "double". (This never...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.