phpsqlsql-serverpdo4d-database

PDO_4D Produces 'General Error: 1004 Failed to execute statement' for UPDATE query but not SELECT queries


I'm using PHP7 and PDO_4D to connect to a 4D database. So far, I've only read from the DB and had not written to it.

The below code block with a SELECT statement will execute without errors.

$db = new PDO($dsn,$user,$pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$sql0 = "SELECT FirstName FROM User WHERE Surname = 'Mouse'";

try {
    $stmt0 = $db->prepare($sql0);
    $stmt0->execute();
} catch (PDOException $e0) {
    echo "Problem with SELECT query:".$e0->getMessage();
}
$results_array0 = $stmt0->fetchAll();

However, the below code block where I'm using an UPDATE query will produce an error.

$sql1 = "UPDATE User SET FirstName = 'Mickey' WHERE Surname = 'Mouse'";

try {
    $stmt1 = $db->prepare($sql1);
    $stmt1->execute();
} catch (PDOException $e1) {
    echo "Problem with UPDATE query:".$e1->getMessage();
}

The error:

SQLSTATE[HY000]: General error: 1004 Failed to execute statement.

According to 4D SQL documentation the Generic Error: 1004 corresponds to 'access denied'. My suspicion was that the 4D server is restricting SQL statements that require WRITE access.

Looking at the 4D Server, I see only this; 4D SQL Server Settings

Are there any additional changes I need to make to the 4D SQL Server in order to execute UPDATE queries? Or am I missing something?


Solution

  • Yes, the 4D developer needs to grant you access. It's just 1 line of code.

    Greetings, Peter