Databases| SQL| MySQL| Questions? | Software Development
 

PHP SQL Null

The result produced by SQL SELECT command may contain NULL or non-Null values. So when we need to work on these values then the NULL values may not work properly.

PHP SQL Null

                         

This example describes about handling NULL values in sql query in php.

The result produced by SQL SELECT command may contain NULL or non-Null values. So when we need to work on these values then the NULL values may not work properly.

MySQL provides some operators to handle the problem.

 

 

 

 

  • IS NULL: This operator returns true if column value is NULL.

  • IS NOT NULL: This operator returns true if column value is not NULL.

Table: tutorial

Source Code of sql_null.php 

<?php
  $dbhost = "localhost";
  $dbuser = "root";
  $dbpass = "root";
  $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  if(! $conn ){
    die("Could not connect: " . mysql_error());
  }
  
  if(isset($t_count)){
    $sql = 'SELECT t_author, t_count FROM  tutorial WHERE t_count IS NULL';
  else {
    $sql = 'SELECT t_author, t_count FROM  tutorial WHERE t_count IS NOT NULL';
  }

  mysql_select_db("test");  
  $result = mysql_query$sql, $conn );
  if(! $result ){
    die("Could not get data: " . mysql_error());
  }
  while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    echo "Author: ".$row['t_author']."<br>""Count: ".$row['t_count']."<br>""<br>";
  }
  echo "Fetched data successfully\n";
  mysql_close($conn);
?>

Download Source Code

Output:

                         

» View all related tutorials
Related Tags: sql mysql c string com function fun io sed const char int ai padding length character case cas if ie

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.