colshrapnel / safemysql

A real safe and convenient way to handle MySQL queries.
Apache License 2.0
395 stars 197 forks source link

Support for enum() and proper error output? #38

Closed jeesus closed 7 years ago

jeesus commented 7 years ago

Hey

Nice class you have here. Though is there going to be any updates to this project? Currently I'm missing a way to update enum field types. Also, seems that errors are not accessible. Or are they added to stats property?

colshrapnel commented 7 years ago

Hello jeesus!

Thank you for your feedback.

Can you please be more specific on your problem with enum field update? In general, there is nothing special with such an update. Here is a code you can try:

include 'safemysql.class.php';
$db = new safemysql();

$db->query("CREATE temporary TABLE enumtest (id int, size enum('small','large'))");
$db->query("INSERT INTO enumtest VALUES (1, 'small')");
var_dump($db->getOne("SELECT size FROM enumtest WHERE id=1"));
$db->query("UPDATE enumtest SET size=?s WHERE id=?s", 'large',1);
var_dump($db->getOne("SELECT size FROM enumtest WHERE id=1"));

for me it outputs

    string(5) "small"
    string(5) "large"

so the update was successful.

As of the error reporting, the current version just throws an exception on mysql error. You should be able to see an uncaught exception, just like any other PHP error. What particular error you cannot access?

jeesus commented 7 years ago

Yeah, thanks, I can see that your provided code works, I can't remember exactly anymore, what went wrong, but now it's working. Sorry for bothering.