# How to modify sql\_mode or Strict Mode in MySQL?

There are cases where an application or website requires disabling a restriction of the **sql\_mode** variable in **MySQL**. For example, disabling **"ONLY\_FULL\_GROUP"** or **"STRICT\_TRANS\_TABLES"**.

Since it is not allowed to modify the **sql\_mode** variable on shared hosting servers, you can modify the restrictions with the following **PHP** code examples:

### Removing all restrictions from "sql\_mode" in PDO connections:

```php
<?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();
}
?>

```

{% hint style="warning" %}
Removing all restrictions from **SQL\_MODE** can make your application more vulnerable to errors or unexpected behaviors. It is advisable to review and understand the implications of disabling certain restrictions before doing so in a production environment.
{% endhint %}

### Removing only a specific restriction from "sql\_mode" in PDO connections:

In the following example, we will only remove the "**ONLY\_FULL\_GROUP\_BY**" restriction.

```php
/<?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);

    // Remove ONLY_FULL_GROUP_BY from SQL_MODE
    $pdo->exec("SET SESSION sql_mode = sys.list_drop(@@SESSION.sql_mode, 'ONLY_FULL_GROUP_BY')");

    // Verify the change
    $stmt = $pdo->query("SELECT @@SESSION.sql_mode");
    $sql_mode = $stmt->fetchColumn();
    echo "Current SQL_MODE: " . $sql_mode;

} catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}
?>

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sitioshispanos.com/menu-principal/guias/web-hosting/soluciones-a-problemas-de-hosting/como-modificar-sql_mode-o-strict-mode-en-mysql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
