[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Transitioning to PDO/MySQL.  Need help  with error. Column cannot be null

Posted on 2014-12-19
3
Medium Priority
?
198 Views
Last Modified: 2014-12-19
I am getting an error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'specs6' cannot be null'

How do you allow null values in PDO?

$statement = $conn->prepare("INSERT INTO specsdownload(sku,specs1,specs2,specs3,specs4,specs5,specs6) VALUES(:sku,:specs1,:specs2,:specs3,:specs4,:specs5,:specs6)");
$statement->execute(array(
    "sku" => $data[0],
       "specs1" => $data[1],
	"specs2" => $data[2],
	"specs3" => $data[3],
	"specs4" => $data[4],
        "specs5" => $data[5],
	"specs6" => $data[6]
));

Open in new window

0
Comment
Question by:lawrence_dev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 200 total points
ID: 40510278
In your data table definition, 'specs6' is probably defined as 'Not Null'.  So in "specs6" => $data[6] you need to provide a default value for $data[6] so that it is never null.
0
 
LVL 58

Accepted Solution

by:
Gary earned 1800 total points
ID: 40510317
Just to follow on from Dave correct observation, to get around the error replace

    "specs6" => $data[6]

with

    "specs6" => isset($data[6])?$data[6]:""

That will just add a blank value to the field, else allow IsNull in the field
0
 

Author Closing Comment

by:lawrence_dev
ID: 40510393
Worked great!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question