本文整理汇总了PHP中Sql::numRows方法的典型用法代码示例。如果您正苦于以下问题:PHP Sql::numRows方法的具体用法?PHP Sql::numRows怎么用?PHP Sql::numRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sql
的用法示例。
在下文中一共展示了Sql::numRows方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: userExists
/**
* Checks if an user exists
* @param string $id_field Field to identify the user with
* @return bool Returns true if the query was successful
*/
static function userExists($id_field)
{
if (!Text::validate($id_field, 'num')) {
$quote = "'";
} else {
$quote = '';
}
if (Sql::numRows("SELECT " . self::$id_field . " FROM accounts WHERE " . self::$id_field . " = " . $quote . $id_field . $quote) < 1) {
return false;
} else {
return true;
}
}
示例2: execute
/**
* Parses the template and executes the listing
* @return void Prints the listing
*/
public function execute()
{
if ($this->template == null) {
Kernel::Log('There\'s no template, cannot generate listing');
return false;
} else {
$columns = Text::parseStringVar($this->template);
foreach ($columns as $key => $i) {
if (in_array($i, array_keys($this->vars))) {
unset($columns[$key]);
}
}
if (isset($this->options['max_regs']) && isset($this->options['page_index'])) {
if ($this->options['max_regs'] < 2) {
Kernel::Log('The max_regs option must be higher than 1');
return false;
}
$rows_page = $this->options['max_regs'];
$index = $this->options['page_index'];
if (isset($this->options['criteria'])) {
$this->options['criteria'] = ' ' . $this->options['criteria'];
} else {
$this->options['criteria'] = '';
}
$rows = Sql::numRows('SELECT ' . implode(', ', $columns) . ' FROM ' . $this->table . $this->options['criteria']);
if (!isset($this->options['template_pag'])) {
$pag = new HTMLObj('div');
$pag->class = "sonicwulf_pages";
} else {
$pag_html = '';
}
for ($i = 0; $i <= ceil($rows / $this->options['max_regs']) - 1; $i++) {
if (!isset($this->options['template_pag'])) {
$div = $pag->addChild('a');
$div->addContent($i);
$div->href = $_SERVER['PHP_SELF'] . '?' . $this->options['get_name'] . '=' . $i;
$div->class = 'sonicwulf_pagenum';
} else {
$parse = Text::parseStringVar($this->options['template_pag']);
if (in_array('href', $parse)) {
$pag_html .= str_replace('%page_link%', $_SERVER['PHP_SELF'] . '?' . $this->options['get_name'] . '=' . $i, $this->options['template_pag']);
} else {
Kernel::Log('There\'s no HREF attribute on the template, please add the atrribute');
return false;
}
}
}
if (!isset($this->options['template_pag'])) {
$pag_html = $pag->executeNoFormat();
}
} else {
$rows_page = null;
$index = null;
$pag_html = null;
}
foreach ($this->getQuery($columns, $rows_page, $index) as $reg) {
$string = $this->template;
foreach ($columns as $i) {
if (isset($reg[$i])) {
$string = str_replace("%" . $i . "%", $reg[$i], $string);
}
}
foreach ($this->vars as $key => $i) {
if (is_array($i)) {
$data = Sql::fetch("SELECT " . $i[0] . " FROM " . $i[1] . $i[2]);
$string = str_replace("%" . $key . "%", $data[0][$i[0]], $string);
} else {
$string = str_replace("%" . $key . "%", $i, $string);
}
}
echo $string;
}
echo $pag_html;
}
}
示例3: setSitevar
/**
* Sets a sitevar from the database
* @param string $var Name of the variable to work with
* @param string $value New value of the variable
* @return bool Returns true if the query was successful
*/
static function setSitevar($var, $value)
{
if (Sql::numRows("SELECT name FROM sitevars WHERE name = '" . $var . "'") > 0) {
return Sql::Update('sitevars', array("value" => $value), "WHERE name = '" . $var . "'");
} else {
return Sql::Insert('sitevars', array("name" => $var, "value" => $value));
}
}