本文整理汇总了PHP中SelectQuery::__toString方法的典型用法代码示例。如果您正苦于以下问题:PHP SelectQuery::__toString方法的具体用法?PHP SelectQuery::__toString怎么用?PHP SelectQuery::__toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SelectQuery
的用法示例。
在下文中一共展示了SelectQuery::__toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toSql
function toSql(SelectQuery $obj)
{
$_string = $obj->__toString();
$_conditions = $obj->conditions();
$_tables = $obj->getTables();
$_fields = $obj->getFields();
foreach ($_tables as $k => $t) {
if (!empty($t['alias'])) {
$_string = str_replace('{' . $t['table'] . '}', $t['table'] . ' as', $_string);
} else {
$_string = str_replace('{' . $t['table'] . '}', $t['table'], $_string);
}
}
foreach ($_conditions as $k => $c) {
if (is_int($c['value'])) {
$_string = str_replace(':db_condition_placeholder_' . $k, $c['value'], $_string);
} else {
$_string = str_replace(':db_condition_placeholder_' . $k, "'" . $c['value'] . "'", $_string);
}
}
return $_string;
}
示例2: Load
/**
* Loads a Model using SQL.
*
* All field values will be loaded from DB.
* @param string $where WHERE-part of the SQL statement.
* @param array $arguments Arguments used in $where
* @return boolean true if dataset was found, else false
*/
public function Load($where, $arguments = false)
{
$q = new SelectQuery($this, $this->_ds);
$sql = $q->__toString() . " WHERE " . $where;
if ($arguments !== false && !is_array($arguments)) {
$arguments = array($arguments);
}
$q = $this->_ds->ExecuteSql($sql, $arguments);
if ($q->rowCount() > 0) {
foreach ($this->GetColumnNames() as $col) {
$this->{$col} = $q[$col];
}
$this->_query = false;
$this->_results = false;
$this->_index = 0;
$this->__init_db_values();
return true;
} else {
$this->__init_db_values(true);
}
return false;
}