Mercurial > hg > fapweb
comparison msitegen.inc.php @ 1108:c7093ad17858
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 16 May 2019 21:57:32 +0300 |
parents | 0a2117349f46 |
children | ac3bd4e94555 |
comparison
equal
deleted
inserted
replaced
1104:0a2117349f46 | 1108:c7093ad17858 |
---|---|
544 } | 544 } |
545 return $dbh; | 545 return $dbh; |
546 } | 546 } |
547 | 547 |
548 | 548 |
549 function stConnectSQLDB() | |
550 { | |
551 global $db; | |
552 try { | |
553 $db = new PDO(stGetSetting("sqlDB"), | |
554 stGetSetting("sqlUsername", NULL), | |
555 stGetSetting("sqlPassword", NULL), | |
556 stGetSetting("sqlOptions", array())); | |
557 } | |
558 catch (PDOException $e) { | |
559 stLogError("Could not connect to SQL database: ".$e->getMessage()."."); | |
560 return FALSE; | |
561 } | |
562 return ($db !== FALSE); | |
563 } | |
564 | |
565 | |
549 function stDBGetSQLParam($dbh, $type, $value) | 566 function stDBGetSQLParam($dbh, $type, $value) |
550 { | 567 { |
551 switch ($type) | 568 switch ($type) |
552 { | 569 { |
553 case "d": return intval($value); | 570 case "d": return intval($value); |
559 case "B": return intval(stGetRequestItem($value)) ? 1 : 0; | 576 case "B": return intval(stGetRequestItem($value)) ? 1 : 0; |
560 } | 577 } |
561 } | 578 } |
562 | 579 |
563 | 580 |
564 function stConnectSQLDB() | 581 function stDBPrepareSQLUpdate($dbh, $table, $cond, $pairs, $values = NULL) |
565 { | 582 { |
566 global $db; | 583 $sql = []; |
567 try { | |
568 $db = new PDO(stGetSetting("sqlDB"), | |
569 stGetSetting("sqlUsername", NULL), | |
570 stGetSetting("sqlPassword", NULL), | |
571 stGetSetting("sqlOptions", array())); | |
572 } | |
573 catch (PDOException $e) { | |
574 stLogError("Could not connect to SQL database: ".$e->getMessage()."."); | |
575 return FALSE; | |
576 } | |
577 $db = stConnectSQLDBSpec(stGetSetting("sqlDB")); | |
578 return ($db !== FALSE); | |
579 } | |
580 | |
581 | |
582 function stDBPrepareSQLUpdate($dbh, $table, $cond, $pairs) | |
583 { | |
584 $sql = array(); | |
585 foreach ($pairs as $name => $attr) | 584 foreach ($pairs as $name => $attr) |
586 { | 585 { |
587 $sql[] = $name."=".stDBGetSQLParam($dbh, $attr, $name); | 586 $sql[] = $name."=".stDBGetSQLParam($dbh, |
587 $attr, $values !== NULL ? $values[$name] : $name); | |
588 } | 588 } |
589 return | 589 return |
590 "UPDATE ".$table." SET ".implode(",", $sql). | 590 "UPDATE ".$table." SET ".implode(",", $sql). |
591 ($cond != "" ? " ".$cond : ""); | 591 ($cond != "" ? " ".$cond : ""); |
592 } | 592 } |