Re: Noobie starting to learn OOP for databases needs help
| From: | David OBrien | Date: | Mon, 17 Dec 2012 00:23:49 +0000 |
| Subject: | Re: Noobie starting to learn OOP for databases needs help | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319903@lists.php.net to get a copy of this message | ||
On Sun, Dec 16, 2012 at 2:08 PM, Matijn Woudt <tijnema@gmail.com> wrote:
> On Sun, Dec 16, 2012 at 4:38 PM, dealTek <dealtek@gmail.com> wrote:
>
> > Hi all,
> >
> > Noobie starting to learn oop for databases from here:
> >
> >
> >
>
> https://github.com/JeffreyWay/PHP-MySQL-Database-Class/blob/master/MysqlDb.php
> >
> > I've got lots working but have a few issues:
> >
> > 1 - after an insert I'd like to get the id of the new record and I'm not
> > sure how to get that...
> >
> > mysql_insert_id (depricated?) or mysqli_insert_id() (I am using mySql
> 5.3)
> >
> > not sure where to add this... (most likely in MysqlDb.php but I don't
> know
> > where or how...)
> >
> > http://de.php.net/manual/en/function.mysql-insert-id.php
>
>
>
> try SELECT LAST_INSERT_ID();
> it should give you the id of the last inserted row (on a connection basis).
>
>
>
> >
> >
> > 2 - how does one do aggrigate select queries like "SELECT SUM(price) FROM
> > mytable" ... what I tried seemed to fail...
> >
> >
> Please show is exact query that failes, and give the error it returns.
>
>
> >
> > And if anyone can point to some good OOP training URL's I'd appreciate
> it.
> >
> > Thanks in advance for any assistance...
> >
> >
> Note sure what OOP has to do with MySQL, but I'd say google for PHP OOP and
> there's plenty of good stuff available.
>
> - Matijn
>
I'd do
select sum(price) as price
that way the column name returned is "price" and not a derived column name