-2

I want to know if is possible to do the following in a simpler way:

$MyConn = new mysqli($host,$User,$Pass);
$TheKey = "...blablabla";
$QueryConvertedKey = "SELECT PASSWORD('".$TheKey."');";//Or SELECT YEAR(CURRENT_DATE); 
$RsltCK  = $MyConn->query($QueryConvertedKey);

//How to replace the while loop or if?
while ($NewRow = $RsltCK->fetch_row()) { //I think that I don't need to use a while or if for this.
    echo "The Converted Key is:".$NewRow[0];
}

I'm sure the response of my query contains exactly one result, so I don't think I need to use a while loop or if clause.

Is it possible to do this without while and if, in one line of code?

4

2 回答 2

0

要以更简单的方式做到这一点,您需要一个构建在 mysqli 之上的抽象库。因此,您将能够使用旨在从查询中直接获取结果的类方法,省略所有不必要的东西

$db   = new dbal();
$key  = "...blablabla";
$conv = $db->getOne("SELECT PASSWORD(?s)", $key);
echo "The Converted Key is: $conv";
于 2013-04-05T05:54:57.877 回答
-1

在 php5.4 中,您可以在创建实例 /object/ 时调用方法;​​-)。如 :

$RsltCK = new mysqli($host,$User,$Pass)->query($QueryConvertedKey);

但实际上,这不是 oop。您必须创建一个连接器类/连接器必须是单例的,例如仅实例化一次/,然后将其扩展到您的需要。在大多数情况下,简单意味着不是更少的代码,而是简单。易于理解,易于扩展/扩展。

于 2013-04-04T22:30:21.100 回答