如何修复SQLite3中的空记录

时间:2014-05-08 04:11:09

标签: php sqlite wamp arabic

当前环境:

  • 我正在使用WampServer 2.5
  • PHP 5.5.12

我在TEXT

中的sqlite3中获得了所有值的空行

如下所示:

$sql= 'CREATE TABLE ads (
       IDs TEXT,
       Countries TEXT,
       Types TEXT,
       SRs TEXT,
       Infos TEXT,
       Currency TEXT,
       Prices TEXT,
       Mobiles TEXT,
       Images TEXT 
)';

注意:我在ARABIC中插入数据

有任何帮助吗?谢谢。

2 个答案:

答案 0 :(得分:0)

确保将列整理更改为utf8:

ALTER TABLE `ads` CHANGE `IDs` `IDs` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `Countries` `Countries` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `Types` `Types` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `SRs` `SRs` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `Infos` `Infos` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `Currency` `Currency` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `Prices` `Prices` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `Mobiles` `Mobiles` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL ,
CHANGE `Images` `Images` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL 

答案 1 :(得分:0)

首先,请查看pragma.html#pragma_encoding,了解如何设置' sqlite'不同字符集的数据库。我会首先尝试默认值,我相信它是UTF-8。

我建议在PHP中使用PDO是可行的方法。另外,我建议始终使用预备语句和标记变量'这样的驱动程序'做所有的工作。

以下是插入的完整工作示例:

<?php

$dsn = "sqlite:" . 'p:/temp/test.sqlite';
$options = array(
    \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$db = new \PDO($dsn);
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);


$sql = 'INSERT INTO ADS (IDs, Countries, Types, SRs, Infos, Currency, Prices, Mobiles, Images) '
       .' VALUES( :id, :Contry, :type, :sr, :info, :Crouncy, :price, :mobile, :image)';

$statm = $db->prepare($sql);
$allOk = $statm->execute(array( ':id' => '1', ':Contry' => 'uk', ':type' => 'type1',
                           ':sr' => 'sr1', ':info' => 'info1', ':Crouncy' => 'crouncy1',
                           ':price' => 'price1', ':mobile' => 'mobile1', ':image' => 'image1',
         ));

var_dump($allOk);