MySQL update or insert query or query

Is it possible to do something like this, I never see more than one or an operator:

$insert = 'INSERT into fhours (' .$cols . ') VALUES ('.$query.')';
$update = sprintf("UPDATE fhours SET %s WHERE fname='$fname' AND lname='$lname'", $field_list);

$result = $db->query($update) or $db->query($insert) or die('uhoh');`
+1
source share
4 answers

There are two problems with this.

First, you can use parameterized queries. Look at the PDO, this will help you greatly . This not only speeds up the work with multiple inserts, but you do not need to worry about SQL injection.

-, MySQL ON DUPLICATE KEY UPDATE, . , , , . , !

, or .

+3

? . ? .

die() - SQL- - , , , . .

, :

$update_result = $db->query($update);
if(!$update_result) {
  // Yikes! Tell the user something went wrong!
  // Show them an error page or error message
}

$insert_result = db->query($insert);
if(!$insert_result) {
  // Yikes! Tell the user something went wrong!
  // Show them an error page or error message
}

, set_error_handler, PHP , php- :

: assign-op /check/out/my/directory/structure/wp -admin/includes/file.php on line 688

, .

0

, mysql

0

All Articles