1
mjoel
mysql_error - help with mysql query code in xoops
  • 2018/3/24 1:08

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Hi

How do i correct this code below using XOOPS standard ?
what do i replace the mysql error with

sorry im a newbie in coding

$employee_id $xoopsDB->escape($_GET['id']);
$check$xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("employee")." WHERE id='$employee_id' ") or die(mysql_error());

2
Mamba
Re: mysql_error - help with mysql query code in xoops
  • 2018/3/24 4:33

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Richard and I were recently talking about it , so here it is his comment, with some modifications related to your code:

Quote:
While developing, it is nice to have feedback about what is going on. Sitting there with the logger on running your code has a particular set of requirements.

On the other hand, in a production situation, requirements are different. A false return from query() is a bad thing. That represents something seriously wrong with the SQL -- syntax errors, non-existing tables, constraint violations, etc.

The question becomes, what do YOU, as the developer, think is the appropriate response to the error?

In this particular case, the SQL error would already have been logged by the database class - it could seen in the "Queries" panel of the logger. If that is all you want to accomplish, you don't need to do anything more.


$check $xoopsDB->query("SELECT * FROM " $xoopsDB->prefix("employee") . " WHERE id='$employee_id' ");


Quote:
What it doesn't do is put out a message that could be seen by the user, or more significantly, seen when monitoring the site log. If something a user is running is broken, a real message in the log might be a good idea -- you won't have the luxury of seeing that logger. To generate that you need to do at least a trigger_error().


$check $xoopsDB->query("SELECT * FROM " $xoopsDB->prefix("employee") . " WHERE id='$employee_id' ");
if (!
$check) {
    
trigger_error($xoopsDB->error());
}
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

3
mjoel
Re: mysql_error - help with mysql query code in xoops
  • 2018/3/24 5:22

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Thank You Very Much Mamba for the long explanation

4
Mamba
Re: mysql_error - help with mysql query code in xoops
  • 2018/3/24 8:34

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


You need to thank Richard
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

Login

Who's Online

383 user(s) are online (312 user(s) are browsing Support Forums)


Members: 0


Guests: 383


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits