Skip to content

CURRENT_TIMESTAMP & $prefix #1046

Description

@sajjadef98

My code has an error when I use prefix and changes the CURRENT_TIMESTAMP variable? What is the problem?
php v =8.4.3
mysqlv=5.7.33
faremework = https://github.com/flare-framework/Flare/

<?php

require_once __DIR__ . '/../app/cli-config.php';

$table = MysqliDb::$prefix . 'users';

if (!$db->tableExists($table)) {
    $query = "
CREATE TABLE IF NOT EXISTS `{$table}` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `name` VARCHAR(100) NOT NULL,
    `email` VARCHAR(150) NOT NULL UNIQUE,
    `password` VARCHAR(255) NOT NULL,
    `token` VARCHAR(255) DEFAULT NULL,
    `photo` VARCHAR(255) DEFAULT NULL,
    `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ";

    echo "🔧 Running SQL:\n$query\n";

    $db->rawQuery($query) ;
    if ($db->tableExists($table)) {
        echo "✅ Table '$table' created successfully.\n";
    } else {
        echo "❌ Failed to create table '$table'.\n";
    }
} else {
    echo "⚠️ Table '$table' already exists.\n";
}
CREATE TABLE IF NOT EXISTS `Ydnujs_users` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `name` VARCHAR(100) NOT NULL,
    `email` VARCHAR(150) NOT NULL UNIQUE,
    `password` VARCHAR(255) NOT NULL,
    `token` VARCHAR(255) DEFAULT NULL,
    `photo` VARCHAR(255) DEFAULT NULL,
    `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
mysqli_sql_exception {#14
  #message: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Ydnujs_CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT
 NULL DEFAULT Ydnujs_CURRENT' at line 1"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions