草庐IT

find-by-sql

全部标签

php - 使用 Symfony 2,Doctrine 在 SQL 数据库中保存数组?

我正在做应用程序,我在其中使用SQL,我想将复选框值保存在一列中。我是这样做的:/***@Assert\NotBlank(*message="pleaseselect!")*@Assert\NotNull(*message="pleaseselect!")*@Assert\Range(min=0,max=9)*@ORM\Column(type="integer")*/protected$ingredients;publicstaticfunctiongetIngredientsOptions(){returnarray('cheese','tomatoes','salami','oni

PHP preg_split : Split string by other strings

我想用一系列单词拆分一个大字符串。例如$splitby=array('these','are','the','words','to','split','by');$text='Thisisthestringwhichneedstobesplitbytheabovewords.';那么结果就是:$text[0]='Thisis';$text[1]='stringwhichneeds';$text[2]='be';$text[3]='above';$text[4]='.';我该怎么做?是preg_split最好的方法,还是有更有效的方法?我希望它尽可能快,因为我将拆分数百MB的文件。

php - 更好的 SQL 字符串清理功能

我目前正在使用以下函数来清理我的$_POST和$_GET以防止SQL注入(inject)。不幸的是,我无法通过它发布代码,例如:“”。推特是怎么做到的?function_secinput($variable){returnfilter_var(mysql_real_escape_string($variable),FILTER_SANITIZE_STRING);}另外,如果我能以任何方式改进它,谁能告诉我建议? 最佳答案 永远不会也永远不会有一个函数来清理所有的东西。您必须为工作选择合适的工具。1)htmlspecialchars(

php - Magento : Get country code by country name

我试图通过国家名称查找国家代码。所以,例如,我有“荷兰”,我需要得到“NL”我知道有一种方法可以找到名称形式的代码:$country_name=Mage::app()->getLocale()->getCountryTranslation($country_code)但我需要反之亦然。那么Magento中有什么方法可以解决吗? 最佳答案 Fromtheotherquestion,这只能通过循环国家集合来完成$countryId='';$countryCollection=Mage::getModel('directory/count

php - 什么是 SQL 支持的数字运算的更好选择 - Ruby 1.9、Python 2、Python 3 或 PHP 5.3?

“更好”的标准:数学速度快,简单(字段少,记录多)数据库事务,开发/读取/扩展方便,灵活,可连接。任务是使用一种通用的网络开发脚本语言来处理和计算长时间序列和多维表面(主要是选择/插入一组float并用它们进行数学计算)。选择是Ruby1.9、Python2、Python3、PHP5.3、Perl5.12或JavaScript(node.js)。所有数据都将存储在关系数据库中(由于其高度多维的性质);所有与外部世界的通信都将通过网络服务完成。 最佳答案 我建议使用Python及其出色的科学/数学库(SciPy、NumPy)。否则语言

php - 是否有 PHP Array Group By 函数?

$arr1=array('a'=>'1','b'=>'blah','c'=>'whatever...','aa'=>'2','bb'=>'lbha','cc'=>'everwhat...','dd'=>'bingo','aaa'=>'3','bbb'=>'halb','ccc'=>'revetahw...');在数组中我有三个不同的索引长度a,b和c的长度都是1。aa,bb,cc和dd的长度都是2。而aaa,bbb,ccc的长度都是3。我想做的是找到元素最多、长度最长的索引(按长度分组)。所以我会使用aa、bb、cc、dd,因为它们有4个元素,这将返回索引长度2。我想知道如何获得2?这

php - 从sql server日期时间中获取日期

我需要从SQLServerdatetime获取日期,然后格式化日期。(即01-Jan-2000)我正在使用PHP。目前,SQL正在返回2009-02-1322:00:00.000。 最佳答案 echodate('d-M-Y',strtotime($datetime_from_db)); 关于php-从sqlserver日期时间中获取日期,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/question

php - 错误 : Call to a member function find() on a non-object in cakephp controller

我是cakephp的新手,并尝试使用控制台工具生成一些CRUD操作。它工作正常,除了一张table(最大的)。尝试添加新元素时,返回:Error:Calltoamemberfunctionfind()onanon-objectFile:C:\wamp\www\cakephp\app\Controller\ChantiersController.phpLine:50这是第50行及以后的代码:$programs=$this->Chantier->Program->find('list');$etats=$this->Chantier->Etat->find('list');$types=$

PHP preg_split : Split string by forward slash

我想使用PHP函数preg_split通过正斜杠拆分我的字符串192.168.1.1/24.我的变量:$ip_address="192.168.1.1/24";我试过了:preg_split("/\//",$ip_address);//Andpreg_split("/[/]/",$ip_address);Errormessage:preg_split():Delimitermustnotbealphanumericorbackslash我在stackoverflow中找到了以下答案Phppreg_splitforforwardslash?,但它没有提供直接的答案。

php - 哪个更好 : filter using SQL or PHP?

情况:每个用户只能看到特定国家和特定代理商的销售报告。那么,哪个更好:$reports=$DB->select('fields'=>'*','table'=>'sales','where'=>array('sales_date'=>array('2011-06-02','2011-06-04'),'sales_country'=>array_keys($allow_country),'sales_agent'=>array_keys($allow_agent)));或者:$result=$DB->select('fields'=>'*','table'=>'sales','where'