2
votes

Hi guys I need help for SQLite - sqlite_escape_string() in PHP. Here is a Code:

<?php
require_once('AES/AES_Encryption.php');
require_once('AES/padCrypt.php');

$database = new PDO('sqlite:example_sqlite3.db');

$key = "bac09c63f34c9845c707228b20cac5e0";   
$iv = "1234567890123456";                    
$AES = new AES_Encryption($key, $iv);

$Col1 = '123456789qwerty';
$Col2 = 'qwerty123456789';

$encrypted_1 = sqlite_escape_string($AES->encrypt($Col1));
$encrypted_2 = sqlite_escape_string($AES->encrypt($Col2));

INSERT INTO AES_T (encrypted_1 , encrypted_2 ) VALUES ('$encrypted_1', '$encrypted_2');

echo "ENC1:" . $encrypted_1;
echo "ENC2:" . $encrypted_2;
?>

Ok, this ecnryption works in MySQL with mysql_real_escape_string(). Using sqlite_escape_string() it reports: Fatal error: Call to undefined function sqlite_escape_string(). AES PHP encryption: For encryption i am using this: http://www.coderelic.com/2011/10/aes-256-encryption-with-php/

I check phpinfo() and i have enabled:

  • PDO drivers: mysql
  • sqlite ENABLED
  • PDO Driver for SQLite 3.x ENABLED
  • SQLite Library 3.7.7.1 ENABLED
  • SQLite3 support SQLite3 module version 0.7 ENABLED
  • SQLite Library 3.7.7.1 ENABLED

I am using WAMP Server Apache Version 2.22.22 and PHP Version 5.4.3 i tryed with Zend Server and with regular Apache and PHP instalation and its a same error. Please need help about this.

1

1 Answers

5
votes

sqlite_escape_string is deprecated in php 5.4. The best way to escape a database string is to use PDO like suggested here escaping strings for SQLite3 in PHP5