今天我正在浏览php手册并偶然发现一个控制结构声明.
declare构造用于为代码块设置执行指令
这是declare
应该做的.说实话,我不明白.在再次阅读时,它发现了一件新事物Ticks
tick是由声明块内的解析器执行的每N个低级别可勾选语句发生的事件.在声明块的指令部分中使用ticks = N指定N的值.
我也不明白.这是什么意思N low-level tickable statements
如果有一个很好的示例代码,那么它将很容易理解.但手册中没有找到任何内容.我在SO Q1上找到了一些,这实际上增加了我的好奇心和困惑.任何人都可以使用这个,我们可以在哪里使用它.
我的实际困惑在于这个陈述(来自链接的帖子)you can declare a tick-function which checks each n executions of your script whether the connection is still alive or not
.因此,当我在php文件上注册tick = 20的tick函数并执行它时,该文件将处于活动状态,直到20执行完成(当它被错误地视为多线程时得到这个想法).这是我的想法,我不认为它是正确的..
或者它是一个简单的替代品 while($x = 20)
[编辑1]
我也看到了declare()
php手册函数参数的另一部分的实现
[编辑2]
也在过程控制中
您可以使用declare()语句指定程序中允许回调的位置.这允许您最小化处理异步事件的开销
我对USING
用于在 postgres 中连接两个表的关键字感到困惑。我第一次看到它是在另一个 SO 帖子中比较 postgres 中的两个表。我检查了 postgres 2.6的手册。表之间的连接。
我无法理解 postgres 如何识别user_id
要加入的(在 SO 帖子中)
我正在写一个查询,以获得所有球队的所有球员.我没有在应用程序中循环,而是决定使用单个查询来获取所有团队的玩家array_agg()
.我写的查询如下:
SELECT team_id, array_agg(team_name) AS teamname,
array_agg(player_id||'##'||player_name) AS playerdetails
FROM team
INNER JOIN players ON team_id = player_team
GROUP BY team_id
Run Code Online (Sandbox Code Playgroud)
这个查询给我的结果如下,在结果集中teamname
重复(确切地说是玩家的数量)
team_id team_name playerdetails
1 {Australia,Australia,Australia,Australia} {"5##Glenn Donald McGrath","6##Shane Warne","2##Steve Waugh","1##Adam Gilchrist"}
2 {India,India,India,India} {"8##Kapil Dev","11##Saurav Ganguly","3##Rahul Dravid","9##Sachin Tendulkar"}
3 {"South Africa","South Africa","South Africa","South Africa"} {"12##Gary Kristen","4##Shaun Pollock","7##Jacques Kallis","10##Alan Donald"}
Run Code Online (Sandbox Code Playgroud)
有没有办法像这样返回结果
team_id team_name playerdetails
1 Australia {"5##Glenn Donald McGrath","6##Shane Warne","2##Steve Waugh","1##Adam Gilchrist"}
Run Code Online (Sandbox Code Playgroud)
我使用子查询实现了它,但想知道是否可以在没有子查询的情况下编写它
SELECT team_id, teamname[1], playerdetails
FROM (
SELECT team_id, array_agg(team_name) AS teamname,
array_agg(player_id||'##'||player_name) …
Run Code Online (Sandbox Code Playgroud) 我如何指定Zend Db Table Select
获取虚拟列.
我想生成这样的SQL
SELECT 'ABC' AS xyz , name FROM employee
编辑:
我试过这个
$select->from('employee',array(
'xyz'=>'ABC',
'name'
));
Run Code Online (Sandbox Code Playgroud)
还有
$select->from('employee',"'ABC' AS xyz , name"));
在两种情况下,Zend都会智能地将"ABC"视为模式中的一个字段.所以它产生类似的东西
SELECT `employee`.`'ABC'` AS `xyz` , `name` FROM `employee`
Run Code Online (Sandbox Code Playgroud)
这会产生错误,因为ABC不是员工的一个领域
我有这样的JS stirng
<div id="grouplogo_nav"><br> <ul><br> <li><a class="group_hlfppt" target="_blank" href="http://www.hlfppt.org/">&nbsp;</a></li><br> </ul><br> </div>
我需要删除所有<br>
与$nbsp;
那些只之间>
和<
.我试着写一个正则表达式,但没有把它弄好.有没有人有解决方案.
编辑:
请注意我只想删除标签b/w >
和<
我正在实现一个请求机制,用户必须批准请求.为此我已经实现了临时表和主表.最初在添加请求时,数据将被插入到临时表中,在批准后它将被复制到主表中.
问题是,批准后将有超过5k行移动到主表,详细信息表中的每一行将有另外3-5行(存储详细信息).我目前的实现是这样的
//Get the rows from temporary table (batch_temp)
//Loop through the data
//Insert the data to the main table (batch_main) and return the id
//Get the details row from the temporary detail table (batch_temp_detail) using detail_tempid
//Loop through the data
//Insert the details to the detail table (batch_main_detail) with the main table id amount_id
//End Loop
//End Loop
Run Code Online (Sandbox Code Playgroud)
但是这个实现将至少需要20k个查询.有没有更好的方法来实现相同的.
我试图创建一个sqlfiddle但无法创建一个.所以我在pgsql.privatepaste.com中粘贴了查询
我正在处理带有项目列表的表格。对于每个项目,都会有一个父项目。树形结构也是如此。
我需要获取项目的完整详细信息,例如Item 1 >> Item 1.1 >> Item 1.1.1 >> Item 1.1.1.1 >> Item 1.1.1.1.1所以我决定创建一个函数,当我们传递项目的 id,在Item 1.1.1.1.1的示例 id 中
CREATE TABLE item (
item_id bigint,
item_name text,
item_code text,
item_parentid bigint
);
INSERT INTO item VALUES (1, 'Item 1', 'Item 1', NULL);
INSERT INTO item VALUES (2, 'Item 1.1', 'Item 1.1', 1);
INSERT INTO item VALUES (3, 'Item 1.1.1', 'Item 1.1.1', 2);
INSERT INTO item VALUES (4, 'Item 1.1.1.1', 'Item 1.1.1.1', 3);
INSERT INTO item VALUES …
Run Code Online (Sandbox Code Playgroud) sql postgresql stored-procedures common-table-expression postgresql-8.4
我已将 symfony 应用程序更新为5.1.3。但是从那以后,清除缓存时出现了一个类丢失异常。
In App_KernelDevDebugContainer.php line 1050:
Attempted to load class "MappingDriverChain" from namespace "Doctrine\Common\Persistence\Mapping\Driver".
Did you forget a "use" statement for "Doctrine\Persistence\Mapping\Driver\MappingDriverChain"?
Run Code Online (Sandbox Code Playgroud)
我检查了缓存文件,symfony 确实在缓存上请求这个类。从其他一些 SO 帖子中,我得到的印象是学说结构已经改变。我在所有必须进行此更改的存储库类上也遇到了类似的问题
Doctrine\Persistence\ManagerRegistry => Doctrine\Common\Persistence\ManagerRegistry
我看过一个类似的 SO 帖子关于同一问题,说更新到最新版本将解决这个问题。但就我而言,这并不成功。
是 symfony 版本的问题还是其他一些配置问题。
而且我还创建了两个数据库连接,都是 MySQL。不确定这是否与问题有任何联系。
这是我目前的composer.json和composer.lock
我正在尝试使用zend_db_select(ZF 1.12)中的相关子查询构造一个有效的MySql查询,以便在Zend_Paginator_Adapter中使用它.工作查询如下:
SELECT f.*, (SELECT (COUNT(p.post_id) - 1)
FROM `forum_topic_posts` AS p WHERE f.topic_id = p.topic_id) AS post_count
FROM `forum_topics` AS f WHERE f.forum_id = '2293'
ORDER BY post_count DESC, last_update DESC
Run Code Online (Sandbox Code Playgroud)
所以我解决了:
$subquery = $db->select()
->from(array('p' => 'forum_topic_posts'), 'COUNT(*)')
->where('p.topic_id = f.topic_id');
$this->sql = $db->select()
->from(array('f' => 'forum_topics'), array('*', $subquery . ' as post_count'))
->where('forum_id=?', $forumId, Zend_Db::PARAM_INT)
->order('post_count ' . $orderDirection);
Run Code Online (Sandbox Code Playgroud)
但Zend在执行查询时会因以下异常而停止:
Zend_Db_Statement_Mysqli_Exception: Mysqli prepare error: You have an error in your SQL syntax; check the manual that corresponds …
这是我的示例对象
object name: OBJ
object properties: String name, int age
现在我有2个全球名单
List<OBJ> lstobj = new ArrayList<OBJ>;
List<OBJ> anotherlist = new ArrayList<OBJ>;
Run Code Online (Sandbox Code Playgroud)
然后我在这两个列表中添加了一些记录
Name:Ben Age:5
Name:Charles Age: 6
Name:Dan Age:7
现在我需要将查尔斯的年龄改为"10"
首先,我应该在列表中找到Charles并从列表中获取obj
OBJ newobj = new OBJ;
for(OBJ obj : lstobj){
if(obj.getName.equals("Charles"){
newobj = obj;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要将检索到的obj的年龄设置为10.
newobj.setAge(10);
此操作不仅会更改"lstobj",还会更改"其他列表".如何在不影响两个全局列表的情况下设置检索到的obj?
我试图从数组中删除索引,我使用javascript splice
来实现它.但奇怪的事情正在发生.
var dataarray = [{"childid":"1275","id":"5501"},
{"childid":"1276","id":"5501"},
{"childid":"1277","id":"5502"},
{"childid":"1278","id":"5502"},
{"childid":"1279","id":"5501"}
,{"childid":"1280","id":"5501"}];
var temp_dataarray = dataarray;
$.each(dataarray, function(i, data) {
if(data.id != 1275)
{
temp_dataarray.splice(i, 1);
console.log(' Dataarray count : '+dataarray.length);
console.log(' Temp count : '+temp_dataarray.length);
}
});
Run Code Online (Sandbox Code Playgroud)
console.log输出
Dataarray count : 5
Temp count : 5
Dataarray count : 4
Temp count : 4
Dataarray count : 3
Temp count : 3
TypeError: data is undefined
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我并没有改变它,dataarray
但它的数量正在减少.为什么会这样?
我number_format
在5.3和5.4版本上使用时遇到问题
$ number = 1234.56;
echo number_format($ number,2,'.',"");
在5.3中给出输出为1和234.56
但在5.4中输出为1 234.56
任何人都可以建议我解决它.
我需要在PostgreSQL 8.4中实现一个正则表达式(据我所知)匹配.似乎正则表达式匹配仅在9.0+中可用.
我的需求是:
当我提供输入时,14.1
我需要得到这些结果:
14.1.1
14.1.2
14.1.Z
...
Run Code Online (Sandbox Code Playgroud)
但排除:
14.1.1.1
14.1.1.K
14.1.Z.3.A
...
Run Code Online (Sandbox Code Playgroud)
该模式不限于单个字符.总有一种可能性,像这样的格局将呈现:14.1.1.2K
,14.1.Z.13.A2
等等,因为该模式提供给用户.应用程序无法控制模式(它不是版本号).
知道如何在Postgres 8.4中实现这一点吗?
再问一个问题我的问题解决了在存储过程中的Postgres 8.4中转义LIKE模式或regexp字符串
php ×5
postgresql ×5
sql ×3
javascript ×2
jquery ×2
regex ×2
zend-db ×2
arraylist ×1
doctrine-orm ×1
java ×1
list ×1
mysql ×1
symfony ×1
symfony5 ×1