Solved

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

Posted on 2014-12-19
3
159 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
3 Comments
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 50 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 450 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now