How to modify sql_mode or Strict Mode in MySQL?
Removing all restrictions from "sql_mode" in PDO connections:
<?php
$dsn = 'mysql:host=localhost;dbname=database_name';
$username = 'username';
$password = 'password';
try {
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Set SQL_MODE to empty
$pdo->exec("SET sql_mode = ''");
// Verify the change
$stmt = $pdo->query("SELECT @@sql_mode");
$sql_mode = $stmt->fetchColumn();
echo "Current SQL_MODE: " . $sql_mode;
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>
Removing only a specific restriction from "sql_mode" in PDO connections:
PreviousWhy can't IonCube activate on shared hosting servers?NextHow to set up forms if the mail() function is disabled?
Last updated
Was this helpful?