Re: [sqlite] What is the exact syntax for SELECT MAX in PHP?

2017-08-05 Thread Simon Slavin


On 5 Aug 2017, at 10:10pm, J. King  wrote:

> Simon, why would you recommend not using PDO? Does the SQLite3 extension 
> perform better, or does it boil down to personal preference?

Good question.  Please allow me slight simplification in the following.

PHP’s SQLite3 extension is a thin shim over SQLite3’s C API.  One PHP method 
for each C call.  It’s the least amount of code you can write to let PHP issue 
SQLite3 calls.  Because of this, it’s extremely fast and uses very little 
memory.  Best of all, if you need documentation for the PHP commands you can 
usually read the documentation for SQLite3’s C API, and in your head convert C 
types to PHP types, etc..

If you know how SQLite3 works then you’ll understand PHP’s SQLite3 extension, 
and it’s the fastest, most efficient way to program.

The PDO extension has to make all commands, types and structures conform to the 
ones already chosen for the PDO extension.  Some of them don’t fit the SQLite 
way of doing things.  For instance, there’s no way of doing the individual 
parts of prepare, step, finalize.  Other commands automatically convert their 
results into different types, taking longer than necessary, using extra memory, 
and losing some distinctions which are important to figure out exactly what’s 
in a SQLite3 database.

However, if you’re already good at PHP, aren’t short of runtime or memory, 
don’t care about picky details of how SQLite works, and/or may want to swap 
between SQLite and a different DBMS, PDO is the way to go.

So it’s horses for courses.  I do keep my eye open for people who say they’re 
using multiple different DBMSes but in the absence of that I generally 
recommend using the SQLite3 module.

Simon.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What is the exact syntax for SELECT MAX in PHP?

2017-08-05 Thread J. King
Simon, why would you recommend not using PDO? Does the SQLite3 extension 
perform better, or does it boil down to personal preference?

On August 5, 2017 1:35:43 PM EDT, Simon Slavin  wrote:
>
>
>On 5 Aug 2017, at 10:53am, Edmondo Borasio 
>wrote:
>
>> Hey, do you know where I can find good instructions on how to use
>SQLITE in
>> PHP?
>
>I used to do that for a living.
>
>First, use the sqlite3 module.  Don’t use the PDO module which can
>access many types of database.  So you should be doing "new SQLite3()"
>like this:
>
>   $db = new SQLite3('mysqlitedb.db');
>   $results = $db->query('SELECT bar FROM foo');
>   while ($row = $results->fetchArray()) {
>   var_dump($row);
>   }
>
>Second, I have not found any better examples than you find in the
>documentation
>
>
>
>which is rather annoying since there aren’t many examples of some
>calls.
>
>Third, I recommend you try to do object-oriented programming in PHP
>where possible, and the sqlite3 module works well with that.  So
>although the call provided is
>
>   $row = $results->fetchArray()
>
>I frequently do
>
>   $row = (object) $results->fetchArray()
>
>and the var_dump line in the above example will show you how this
>changes what you get.
>
>Simon.
>___
>sqlite-users mailing list
>sqlite-users@mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What is the exact syntax for SELECT MAX in PHP?

2017-08-05 Thread Simon Slavin


On 5 Aug 2017, at 10:53am, Edmondo Borasio  wrote:

> Hey, do you know where I can find good instructions on how to use SQLITE in
> PHP?

I used to do that for a living.

First, use the sqlite3 module.  Don’t use the PDO module which can access many 
types of database.  So you should be doing "new SQLite3()" like this:

$db = new SQLite3('mysqlitedb.db');
$results = $db->query('SELECT bar FROM foo');
while ($row = $results->fetchArray()) {
var_dump($row);
}

Second, I have not found any better examples than you find in the documentation



which is rather annoying since there aren’t many examples of some calls.

Third, I recommend you try to do object-oriented programming in PHP where 
possible, and the sqlite3 module works well with that.  So although the call 
provided is

$row = $results->fetchArray()

I frequently do

$row = (object) $results->fetchArray()

and the var_dump line in the above example will show you how this changes what 
you get.

Simon.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What is the exact syntax for SELECT MAX in PHP?

2017-08-05 Thread Edmondo Borasio
Bingo! Many thanks!

Hey, do you know where I can find good instructions on how to use SQLITE in
PHP?
I have searched a lot but haven't found much more than isolated questions
from different users on some forum...

Regards

Edmondo

Dr Edmondo Borasio, MedC BQ Ophth, FEBO
Consultant Ophthalmologist
Specialised in Cornea, Cataract & Laser Refractive Surgery

Head of Corneal and Refractive Surgery Department
Burjeel Hospital
Abu Dhabi, UAE

On 5 August 2017 at 13:29, Tim Streater  wrote:

> On 5 Aug 2017, at 9:35, Edmondo Borasio  wrote:
>
> > $results = $db->query("SELECT MAX(ID) FROM Table")->fetchArray();
> > $Highest_ID = $results['ID'];
> > var_dump($Highest_ID);
> >
> > I get NULL
>
> Try:
>
> $results = $db->query("SELECT MAX(ID) as mx FROM Table")->fetchArray();
>  $Highest_ID = $results['mx'];
>  var_dump($Highest_ID);
>
>
>
>
> --
> Cheers  --  Tim
> ___
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What is the exact syntax for SELECT MAX in PHP?

2017-08-05 Thread Tim Streater
On 5 Aug 2017, at 9:35, Edmondo Borasio  wrote:

> $results = $db->query("SELECT MAX(ID) FROM Table")->fetchArray();
> $Highest_ID = $results['ID'];
> var_dump($Highest_ID);
>
> I get NULL

Try:

$results = $db->query("SELECT MAX(ID) as mx FROM Table")->fetchArray();
 $Highest_ID = $results['mx'];
 var_dump($Highest_ID);




--
Cheers  --  Tim
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users