htmlentities和htmlspecialchars拒绝处理字符串(htmlentities and htmlspecialchars refuse to process string)
自从我在Debian盒子上最后一次更新到PHP5 5.4.0-3以来,我注意到有些页面有空字段,其中MySQL数据库的文本应该是。
我玩了一下,发现了问题。
<?php $scselect = mysql_query("SELECT `name` FROM `forum_threads` WHERE `forum` = '1' ORDER BY `timestamp` DESC") or exit((mysql_error())); while ($scrow=mysql_fetch_array($scselect)) { var_dump($scrow['name']); var_dump(htmlentities($scrow['name'])); } ?>
奇怪的是这是印刷的:
string(18) "php hu3: the Forum" string(0) "" string(18) "php hu2 score-rule" string(0) "" string(6) "php hu" string(0) "" string(15) "HU 8: Binarycnt" string(0) ""
但如果我使用硬编码内容的htmlentities - > htmlentities(“test”); 它就像魅力一样。 如果我这样做:
var_dump("a".$scrow['name']);
它还说
string(0) ""
但它变得陌生。 如果我将htmlentities或htmlspecialchars与数据库中的任何其他变量一起使用,它就可以完美地运行。
var_dump(htmlspecialchars($scrow['ID'])); // prints for example string(2) "87"
这可能是什么原因?
Since the last update to PHP5 5.4.0-3 on my Debian box I noticed that some pages have empty fields where text from the MySQL database should be.
I played around a bit and found the problem.
<?php $scselect = mysql_query("SELECT `name` FROM `forum_threads` WHERE `forum` = '1' ORDER BY `timestamp` DESC") or exit((mysql_error())); while ($scrow=mysql_fetch_array($scselect)) { var_dump($scrow['name']); var_dump(htmlentities($scrow['name'])); } ?>
strangely this is whats printed:
string(18) "php hu3: the Forum" string(0) "" string(18) "php hu2 score-rule" string(0) "" string(6) "php hu" string(0) "" string(15) "HU 8: Binarycnt" string(0) ""
but if I use htmlentities with hardcoded content -> htmlentities("test"); it works like charm. Also if I do this:
var_dump("a".$scrow['name']);
it also says
string(0) ""
But it gets stranger. If I use htmlentities or htmlspecialchars with any other variable from the database it works just perfectly.
var_dump(htmlspecialchars($scrow['ID'])); // prints for example string(2) "87"
what can be the cause of this?
原文:https://stackoverflow.com/questions/10054513
最满意答案
我认为Criteria部分并不完全正确。 也没有定义日。 你已经定义了DT。
string customer_id = "54sdfjghwegFDqwgf"; DateTime day = DateTime.Parse("2011-10-31"); var criteria = TheSession.CreateCriteria(typeof(user_data)) .Add(Restrictions.Eq("user_id", customer_id)) .Add(Restrictions.Eq("Day", day)) .List<user_data>();
Thanks to everyone who tried to help me out!
Unfortunately, I had to use raw sql query: using CreateSQLQuery and then adding Scalars for each field.
相关问答
更多-
NHibernate COALESCE问题(NHibernate COALESCE issue)[2022-07-16]
草拟的代码应如下所示: // left side var left = Projections.Property(ti => ti.PeriodFrom); // right side var right = Projections.SqlFunction("COALESCE" , NHibernateUtil.DateTime , Projections.Constant(search.DateFrom, NHibernateUtil.Date ... -
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
这有点令人讨厌,但您也可以使用ADDTIME()以负值: SELECT * FROM table WHERE date_col> ADDTIME(NOW(),'-0:5:0'); It's kind of nasty, but you can also use ADDTIME() with a negative value: SELECT * FROM table WHERE date_col > ADDTIME(NOW(), '-0:5:0');
-
string dt; string dt2; DateTime date = DateTime.Now; DateTime date2 = DateTime.Now; dt = date.ToLongTimeString(); // display format: 11:45:44 AM dt2 = date2.ToShortDateString(); // display format: 5/22/2010 ...
-
NHibernate是一个对象/关系映射器,因此要正确地询问“我该如何编写此查询”问题,您需要提供足够的信息,以便潜在的回答者可以理解这三件事情是什么样的: NHibernate实体类(这是Object部分) 数据库表(这是关系部分) 映射 ,无论是HBM.XML,FluentNH等。 让我们假设您的实体看起来像这样: public class AccountProfile { public virtual int Id { get; set; } public virtual string ...
-
NHibernate MySQL Enum(NHibernate MySQL Enum)[2021-11-16]
您可以在C#中使用bool,并使用自定义IUserType实现将其映射到MySQL中的字符。 这个例子正是你想要的。 You can use a bool in C# and map it to a char in MySQL using a custom IUserType implementation. This example is exactly what you're looking for. -
所以我发现了问题,当我安装MySQL时发生了一些事情并且c#连接工具没有正确安装。 一旦卸载Mysql连接C#并树脂安装它,更新项目引用并且它工作。 So I have identified the problem, when I installed MySQL something happened and the c# connection tools did not install correctly. Once Uninstalled Mysql connect for C# and resinsta ...
-
我认为Criteria部分并不完全正确。 也没有定义日。 你已经定义了DT。 string customer_id = "54sdfjghwegFDqwgf"; DateTime day = DateTime.Parse("2011-10-31"); var criteria = TheSession.CreateCriteria(typeof(user_data)) .Add(Restrictions.Eq("user_id", customer_id)) .Add(Restr ...
-
在DateTime/Time/DateTimeOffset/Date数据类型中,我总是明确地告诉映射中的预期类型,因为从底层属性类型(.Net缺少Date类型,...)推断时可能存在一些歧义。 通常对于db DateTime ,我在属性映射上指定NHibernate类型timestamp 。 请参阅NHibernate参考文档中可用的类型列表。 根据您的使用情况,有许多可供选择的类型。 您也可以指定一些非NHibernate类型,如NHibernate参考文档中所述 。 On DateTime/Time/D ...
-
没有必要存储您的数字和DateTime值。 你有一个坏习惯踢 。 将列更改为整数类型和日期时间类型。 并且没有必要在列名中使用单引号。 只需删除它们。 还可以使用using语句自动配置连接,命令和阅读器,而不是手动调用Close方法。 using(var con = new MySqlConnection(conString)) using(var stm = con.CreateCommand()) { stm.CommandText = "SELECT * FROM history WHERE n ...