FluentPDO::from PHP Method

from() public method

Create SELECT query from $table
public from ( string $table, integer $primaryKey = null ) : SelectQuery
$table string - db table name
$primaryKey integer - return one row by primary key
return SelectQuery
    public function from($table, $primaryKey = null)
    {
        $query = new SelectQuery($this, $table);
        if ($primaryKey !== null) {
            $tableTable = $query->getFromTable();
            $tableAlias = $query->getFromAlias();
            $primaryKeyName = $this->structure->getPrimaryKey($tableTable);
            $query = $query->where("{$tableAlias}.{$primaryKeyName}", $primaryKey);
        }
        return $query;
    }

Usage Example

示例#1
1
<?php

require 'concatToOneFile.php';
require 'FluentPDO.php';
$fpdo = new FluentPDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
$q = $fpdo->from('sometable')->where('1=1');
echo $q->getQuery(), "\n";
var_dump($q->fetchAll());
echo "\n\n";
$q = $fpdo->from('sometable')->select('count(1)')->where('1=1');
echo $q->getQuery(), "\n";
var_dump($q->fetchAll());
echo "\n\n";
$q = $fpdo->query('SELECT * FROM sometable WHERE x=?', array('1'));
echo $q->getQuery(), "\n";
var_dump($q->fetchAll());
echo "\n\n";
All Usage Examples Of FluentPDO::from