Newbaby on Aura needs a little help.

62 views
Skip to first unread message

Ruslan Nesterov

unread,
Aug 3, 2015, 9:04:50 AM8/3/15
to The Aura Project for PHP
Good day,

 Just started exploring the world of Aura :-) So please don't bite me. Trying to move to a next level in PHP programming.
So the first lesson task is to run a query agains a Mysql database. Here is the code i used:

<?php
include '../vendor/autoload.php';

// Init Aura
use Aura\SqlQuery\QueryFactory;
use Aura\Sql\ExtendedPdo;
$query_factory = new QueryFactory('Mysql');
// Init end
// 
// Creating a $select for query: SELECT * FROM TEST_TRAVEL
$select = $query_factory->newSelect();
$select
->cols(array('*'))
->from('test_travel')
;
// Printing a query; it looks like SELECT * FROM `test_travel` - hmm looks good 
echo $select->getStatement();

// PDO Connection

$pdo = new ExtendedPdo(
    'mysql:host=localhost;dbname=test',
    'user',
    'userpass'
);
$sth = $pdo->prepare($select->getStatement());
echo '<br>';
// lets try to fetch sometinh
$result = $pdo->fetchOne($sth);

?>

And nothing :-(
In errors I get 

[Mon Aug 03 06:59:07.813783 2015] [:error] [pid 25766] [client 2.92.128.236:50133] PHP Warning:  PDO::prepare() expects parameter 1 to be string, object given in .../htdocs/vendor/aura/sql/src/ExtendedPdo.php on line 771
[Mon Aug 03 06:59:07.813898 2015] [:error] [pid 25766] [client 2.92.128.236:50133] PHP Fatal error:  Call to a member function execute() on a non-object in .../htdocs/vendor/aura/sql/src/ExtendedPdo.php on line 748
[Mon Aug 03 07:09:51.271233 2015] [:error] [pid 25778] [client 2.92.128.236:50250] PHP Warning:  PDO::prepare() expects parameter 1 to be string, object given in .../htdocs/vendor/aura/sql/src/ExtendedPdo.php on line 771
[Mon Aug 03 07:09:51.271348 2015] [:error] [pid 25778] [client 2.92.128.236:50250] PHP Fatal error:  Call to a member function execute() on a non-object in .../htdocs/vendor/aura/sql/src/ExtendedPdo.php on line 748

Finally lost..





Brandon Savage

unread,
Aug 3, 2015, 9:11:41 AM8/3/15
to aur...@googlegroups.com
Hi there.

There's no need to prepare the statement yourself. ExtendedPDO will do that for you. Just pass your query object directly into $pdo->fetchOne().

Brandon



--
You received this message because you are subscribed to the Google Groups "The Aura Project for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages