English 中文(简体)
VARCHAR(4) 具有4个以上特性
原标题:VARCHAR(4) storing more characters than four

我有一个VARCHAR(4)栏,接收来自超过4个特性的投入的数据。 然而,这是不错的,而且我自然地(或我这样认为)让我的我的我的后勤部停止其性质。

奇怪的是,当我对数据库浏览结果进行观察之后,在PHP(Using the PDO的驾驶员)中,整条插座正在显示,而不仅仅是4个特性。

如果我对我的SQL CLI进行“选举调查”,它只恢复4个特性。 即使在我做我的假设时,只有4个特性显示。

任何可能造成这种奇怪的不一致的想法?

Note that these characters are all numbers.

Edit:根据要求,这里有某种代谢法,代表了储蓄/债务法:

查封:

$data = array(
      name_first4        => $fields[ num ],   
     // name_first4 is the column name with VARCHAR(4)
);
$where = $this->getTable()->getAdapter()->quoteInto( id = ? , $id);
$this->getTable()->update($data,$where);

Fetching, using Zend_Db_Table:

$row = $this->getTable()->fetchRow(
    $this->getTable()->select()->where( id=? ,$data)
);
最佳回答

如果你重新这样做:

  1. Create or load an object $o.
  2. Assign 12345 to the property/column in question.
  3. Save $o and let MySQL truncate the value to 1234 .
  4. Access the property/column in $o and get 12345 back.

然后,你再次看到让你的数据库无声地 man击你的数据的问题之一。

The save succeeds, your object has no idea that MySQL has truncated the data so it keeps the 12345 around rather than reloading that column from the database, and you have inconsistent data on your hands.

如果你依靠我的SQL默地篡夺你的数据,你可能不得不这样做:

  1. Create/load your object.
  2. Updated the properties.
  3. Save the object.
  4. Throw away your local reference to the object.
  5. Load it fresh from the database to make sure you get the real values.

d 我建议对您的物体进行严格鉴定,以避免在MySQL内部出现无声的拖网。 转载于strict ,这也将避免这一问题,但随后,你需要审查和加紧处理和验证你的所有错误和数据(这确实是一种坏事)。

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签