我正在尝试执行一个MYSQL命令,该命令用给定的UserID抓取所有行,按日期对它们进行排序,然后只返回前5个.
排序命令是
ORDER BY date
Run Code Online (Sandbox Code Playgroud)
获得最后5个的命令是
WHERE ROWNUM <= 5
Run Code Online (Sandbox Code Playgroud)
WHERE在ORDER之前,所以它是向后的.所以我想我必须在mysql语句中有一个Mysql语句.
这是我的尝试.我收到别名错误,所以我将AS T1添加到命令中.
SELECT * FROM
(SELECT voting_id, caption_uid, voting_date, rating FROM voting
WHERE user_id = $inUserID AS T1
ORDER BY voting_date)
WHERE ROWNUM <= 5 AS T2;
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我尝试了这个,当我尝试在类"second"中实例化类"first"时出现错误.
类"second"中的注释部分会导致错误.
class first {
public $a;
function __construct() {
$this->a = 'a';
}
}
class second {
//$fst = new first();
//public showfirst() {
//$firsta = $this->first->a;
// echo "Here is first \$a: " . $firsta;
//}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
这导致服务器错误,即使我在类"second"中的所有内容都是类"first"的实例化.
class second {
$fst = new first();
//public showfirsta() {
// $firsta = $this->fst->a;
// echo "Here is first \$a: " . $firsta;
//}
}
Run Code Online (Sandbox Code Playgroud) 我是git的新手,我知道git cherry-pick是如何工作的,但这是我的问题:
最近,我团队中的某个人更改了master中的目录结构,但没有更改另一个分支中的目录结构.
现在,当我对分支中的代码进行更改时,我想将它们(cherry-pick)带入master.这很好,直到master和branch中的目录结构相同.
topDir/some/subdir/file - master
topDir/some/other/subdir/file - branch
文件,其更改将被添加到master中是相同的,但不包含它所包含的目录结构.当我尝试以通常的方式进行樱桃选择时,我得到一个错误:
git checkout master git cherry-pick commit error:pathspec topDir/some/other/subdir/file不存在
现在,在这种情况下采摘樱桃的最佳方式是什么?任何指针都非常感谢.
好.我只是注意到,在同一个场景中,当我做一个挑选时,git足够聪明,可以从提交中正确选择其中一个文件,但不能识别另一个.
要使用我在原始帖子中提到的相同示例:在同一个提交中,topDir/some/subdir/file1,topDir/some/subdir1/file2.
我转到master,它有"file1"和"file2",只是在一个不同的目录结构中:topDir/src/some/subdir/file1 topDir/src/some/subdir1/file2.
现在,如果我做一个挑选,git足够聪明,可以获取file1中的更改,即使这是在不同的dir结构中,但不会获取file2的更改.有什么指针吗?如果有人希望我更清楚,我会很高兴.
所以,我所做的解决问题的方法是做一个樱桃选择,手动更改一个git没有拿起,以及"git commit -C.
假设我有一个会话数组
array(
'boking' = array(
'index1' => 'value1'
'index2' => 'value2'
),
'return' = array(
'index1' => 'value1'
'index2' => 'value2'
),
'search' = array(
'index1' => 'value1'
'index2' => 'value2'
)
)
Run Code Online (Sandbox Code Playgroud)
现在我想删除boking和search
要完成此任务,我已尝试
Session::forget('boking');
Session::forget('search');
Run Code Online (Sandbox Code Playgroud)
它工作正常。
但我想在一个命令中删除这个多键。有没有可能在一个命令中做到这一点?
在我的模式文件中,我定义了一个具有可能元素序列的组.
<group name="argumentGroup">
<sequence>
<element name="foo" type="double" />
<element name="bar" type="string" />
<element name="baz" type="integer" />
</sequence>
</group>
Run Code Online (Sandbox Code Playgroud)
然后我像这样引用这个组:
<element name="arguments">
<complexType>
<group ref="my:argumentGroup"/>
</complexType>
</element>
Run Code Online (Sandbox Code Playgroud)
是否有可能在某个其他方面引用该组但限制它,因此它是一个选择而不是一个序列.我想重用它的位置只允许其中一个元素.
<element name="argument" minOccurs="0" maxOccurs="1">
<complexType>
<group name="my:argumentGroup">
<! -- Somehow change argumentGroup sequence to choice here -->
</group>
<complexType>
</element>
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习PHP OOP,并对如何在我的项目中使用全局数据库类进行了一些研究.从我所看到的,最合适的模式是一个单例,它可以确保始终只存在一个数据库连接.然而,由于这是我第一次使用Singleton模式,我不确定我是否做得对.
这是一个合适的单身人士吗?此代码是否仅确保一个数据库连接?有什么办法可以测试吗?(学会钓鱼的人,他将在余生中获得食物......)
我使用redbean作为我的ORM,这是我如何明确地设置它:
require_once PLUGINPATH.'rb.php';
$redbean= R::setup("mysql:host=192.168.1.1;dbname=myDatabase",'username','password');
Run Code Online (Sandbox Code Playgroud)
我已经基于这个源创建了以下脚本,作为我自己的单例数据库类;
class database {
private $connection = null;
private function __construct(){
require_once PLUGINPATH.'rb.php';
$this->connection = R::setup("mysql:host=192.168.1.1;dbname=myDatabase",'username','password');
}
public static function get() {
static $db = null;
if ( $db === null )
$db = new database();
return $db;
}
public function connection() {
return $this->connection;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
如果我?month=$04在网址和回声中传递$date我继续接收1月而不是它应该是什么(4月).如果我回应$month我得到04这是正确的.这是我一直在使用的代码:
if (isset($_GET['month']) && $_GET['month']!='') {
$month = $_GET['month'];
$date = date('F', $month);
}
echo $date;
Run Code Online (Sandbox Code Playgroud)
对于我的生活,我无法弄清楚为什么它输出不正确.任何帮助非常感谢.
此方法搜索搜索关键字并解析mysql查询,并重写where表达式以包含LIKE%keyword%.
它运作良好,但我不知道它的好或坏做法是否有这么多循环的方法...
private function build_where($query_array, $options)
{
//add WHERE starting point
$where = '';
if(!empty($query_array['WHERE']))
{
//build where array
$where_array = $query_array['WHERE'];
//start the where
$where .= 'WHERE ';
//get columns array
$columns_array = $this->build_columns_array($query_array);
//if there is a search string
if(!empty($options['sSearch']))
{
//check for enabled columns
$i = 0;
$columns_length = count($columns_array);
for($i; $i < intval($columns_length); $i++)
{
//create the options boolean array
$searchable_columns['bSearchable_'.$i] = $options['bSearchable_'.$i];
}
//loop through searchable_columns for true values
foreach($searchable_columns as $searchable_column_key => $searchable_column_val)
{ …Run Code Online (Sandbox Code Playgroud) 我正在寻找一些可以对PHP脚本进行基本测试的工具.
这次我对复杂的测试解决方案不感兴趣,需要为每一段代码编写测试.我对功能测试既不感兴趣.
我期望这个工具做的是指出可能导致无效使用的代码片段:
例如,无效的使用将使用NULL作为对象或数组,或者将boolean作为需要为数组或对象(或NULL)的arguent传递.
此外,它还可能会检查是否使用了"良好做法",即它可能会警告使用它是不安全的if ( $condition ) $doSomething;,如果它找到类似的东西.
为了说明该工具应该检测为"不安全"的代码片段,这里有几个例子.
在这种情况下,$filter可能是NULL,但它用作数组:
<?php
function getList(array $filter = null) {
$sql = '...';
// ...
foreach ( $filter as $field => $value ) {
// ...
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,$res可能是false,但它被用作resource.
<?php
$res = mysql_query('...');
while ( $row = mysql_fetch_assoc($res) ) {
// ...
}
mysql_free_result($res);
Run Code Online (Sandbox Code Playgroud)
这里是相应的"安全"代码片段:
// $filter is used only if it's non-empty; as list …Run Code Online (Sandbox Code Playgroud) 你好。
由于我使用的是共享托管包,并且无法使用 PECL Memcache,因此我希望能提供一些有关使用我自己的小型缓存系统或使用 PEAR Cache_Lite 系统之间的疑虑的提示。
所以这是我的功能:
<?php
//this one create a simple .txt file named by unique query_key string generated width e.g $file_name=md5("SELECT * FROM table"); content of that file is serialized value of mysql return
function write($query_key,$result)
{
global $config;
$new_file_name=md5($query_key);
$result_to_write=serialize($result);
if($handle=opendir($config['cache_dir']))
{
$f=fopen($config['cache_dir'].$new_file_name.'.txt','w+');
fwrite($f,$result_to_write);
fclose($f);
closedir($handle);
}
}
// this one reads content of file (serialized mysql return of unique query_key) if timeout hes not expired, and if it is it return false
function read($query_key,$timeout) …Run Code Online (Sandbox Code Playgroud)