Solved

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

Posted on 2014-12-19
3
174 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 83

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

729 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