문제

Current Environment:

  • I'm using WampServer 2.5
  • PHP 5.5.12

I'm getting empty row in sqlite3 all values in TEXT

As you see below:

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

Note: I'm inserting data in ARABIC

Any help? Thank you.

도움이 되었습니까?

해결책

make sure to change you're column collation to 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 

다른 팁

First, look at pragma.html#pragma_encoding for how to set up an'sqlite' database for different character sets. I would try the default first, which i believe is UTF-8.

I suggest that using PDO, in PHP, is the way to go. Also, i suggest always using prepared statements and 'marker variables' that way the 'driver' does all the work.

Here is a full working example of an insert:

<?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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top