Re: Noobie starting to learn OOP for databases needs help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2012/12/16 dealTek <dealtek@xxxxxxxxx>

> 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...)
>

Instead of "true" let insert() return the id.

And while looking at your code:
- You wrote in your DocBlocks, that the methods returns a boolean 0 or 1.
Beside that this is wrong (0 or 1 are integers) you return either 'true' or
nothing. You should return 'false' as well.
- Returning a boolean to indicate the success of a method only makes sense,
when "not successful" is a valid case, but I guess when 'delete()' fail it
not be treatened as "normal". You should throw an Exception instead. This
also includes: It's not required, that a method returns something in every
case. If "delete()" for example doesn't have to tell something, it
shouldn't.


>
> http://de.php.net/manual/en/function.mysql-insert-id.php
>
> 2 - how does one do aggrigate select queries like "SELECT SUM(price) FROM
> mytable" ... what I tried seemed to fail...
>

Nothing "seems to fail" ;) Either it fails, or not (or it just doesn't
behave, like expected, what I see as "fail" too). So what happens?


>
>
> And if anyone can point to some good OOP training URL's I'd appreciate it.
>
> Thanks in advance for any assistance...
>
>
>
>
>
>
>
> --
> Thanks,
> Dave - DealTek
> dealtek@xxxxxxxxx
> [db-12]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
github.com/KingCrunch

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux