Changeset 11485 for trunk/include/dblayer/functions_mysql.inc.php
- Timestamp:
- Jun 22, 2011, 5:56:19 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/dblayer/functions_mysql.inc.php
r11364 r11485 220 220 if (count($datas) == 0) 221 221 return; 222 222 223 // depending on the MySQL version, we use the multi table update or N update queries 223 224 if (count($datas) < 10) … … 233 234 $separator = $is_first ? '' : ",\n "; 234 235 235 if (isset($data[$key]) and $data[$key] != ='')236 if (isset($data[$key]) and $data[$key] != '') 236 237 { 237 238 $query.= $separator.$key.' = \''.$data[$key].'\''; … … 239 240 else 240 241 { 241 if ( $flags & MASS_UPDATES_SKIP_EMPTY )242 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 242 243 continue; // next field 243 244 $query.= "$separator$key = NULL"; … … 346 347 } 347 348 349 /** 350 * updates one line in a table 351 * 352 * @param string table_name 353 * @param array dbfields 354 * @param array data 355 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 356 * @return void 357 */ 358 function single_update($tablename, $dbfields, $data, $flags=0) 359 { 360 if (count($data) == 0) 361 return; 362 363 $query = ' 364 UPDATE '.$tablename.' 365 SET '; 366 $is_first = true; 367 foreach ($dbfields['update'] as $key) 368 { 369 $separator = $is_first ? '' : ",\n "; 370 371 if (isset($data[$key]) and $data[$key] != '') 372 { 373 $query.= $separator.$key.' = \''.$data[$key].'\''; 374 } 375 else 376 { 377 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 378 continue; // next field 379 $query.= "$separator$key = NULL"; 380 } 381 $is_first = false; 382 } 383 if (!$is_first) 384 {// only if one field at least updated 385 $query.= ' 386 WHERE '; 387 $is_first = true; 388 foreach ($dbfields['primary'] as $key) 389 { 390 if (!$is_first) 391 { 392 $query.= ' AND '; 393 } 394 if ( isset($data[$key]) ) 395 { 396 $query.= $key.' = \''.$data[$key].'\''; 397 } 398 else 399 { 400 $query.= $key.' IS NULL'; 401 } 402 $is_first = false; 403 } 404 pwg_query($query); 405 } 406 } 407 348 408 349 409 /** … … 412 472 413 473 /** 474 * inserts on line in a table 475 * 476 * @param string table_name 477 * @param array dbfields 478 * @param array insert 479 * @return void 480 */ 481 function single_insert($table_name, $dbfields, $insert) 482 { 483 if (count($insert) != 0) 484 { 485 $query = ' 486 INSERT INTO '.$table_name.' 487 ('.implode(',', $dbfields).') 488 VALUES'; 489 490 $query .= '('; 491 foreach ($dbfields as $field_id => $dbfield) 492 { 493 if ($field_id > 0) 494 { 495 $query .= ','; 496 } 497 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 498 { 499 $query .= 'NULL'; 500 } 501 else 502 { 503 $query .= "'".$insert[$dbfield]."'"; 504 } 505 } 506 $query .= ')'; 507 508 pwg_query($query); 509 } 510 } 511 512 /** 414 513 * Do maintenance on all PWG tables 415 514 *
Note: See TracChangeset
for help on using the changeset viewer.