Skip to content
Advertisement

PHP – Issue with PDO using CONCAT() with SQLite

I’m using the same query, through PDO connector, to concatenate string in both: MySQL database and a mirroring SQLite one. Both they have same table same structure etc.

But when the query is executed, MySQL performs the query correctly, while SQLite goes in error thus I get an error 500.

Is there a solution to have it working for both databases please? Here down below the parameterized Query I use.

As I said: Without the line `IP` = CONCAT(IP, :param3), everything is working fine (on MySQL as well as SQLite)

With the line `IP` = CONCAT(IP, :param3), MySQL is correctly concatenated, SQLite crashes

$query = "UPDATE downloaded SET
    `player` = player + 1,
    `when` = :param0,
    `IP` = CONCAT(IP, :param3)
    WHERE who = :param1 AND what = :param2";

$params = array(
    ':param0' => $when_,
    ':param1' => $Email,
    ':param2' => $file,
    ':param3' => $IP_Caller . "<br />"
);

Thanks in advance for your help

Advertisement

Answer

SQLite does not support the function CONCAT().
You will have to use the operator ||:

`IP` = IP || :param3

If you want to use the same code in MySql too, you will have to enable the PIPES_AS_CONCAT mode. This mode is by default disabled so the operator || is just an alias for the logical OR.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement