Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; PDO

I am writing some software right now. Reader’s digest version: users select a package, and enter their name, email, and desired subdomain. A subdomain is then checked to see if someone already registered it and if it is only alphanumeric. I had all of this working using MySQL, but I have decided to make the move to PDO.

The exact wording of the error:

error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The stack trace is all over the place, and I can barely figure out when to begin troubleshooting this. I have checked the other answers here, and they all seem too localized, so here’s the code that produces it, then all of the methods that contain errors. Here we go…

migrate_1401_04_22_12_03_00_users.php

public function up()
{
    $db = Application::$app->database;
    $sql = "CREATE TABLE users (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name(255) NOT NULL,
        first_name(255) NOT NULL,
        last_name(255) NOT NULL,
        email(255) NOT NULL,
        password(255) NOT NULL,
        status TINYINT NOT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )  ENGINE=INNODB;";
    $db->pdo->exec($sql);
}

>Solution :

String field types need to be specified with the keyword VARCHAR

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    first_name VARCHAR(255) NOT NULL,
    last_name VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL,
    password VARCHAR(255) NOT NULL,
    status TINYINT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)  ENGINE=INNODB;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading