Centralize SQL connections

Co-authored-by: LeOSW42 <673670+LeOSW42@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-24 12:48:16 +00:00
parent 041e77246f
commit 92555ea2bf
7 changed files with 65 additions and 83 deletions

View File

@@ -11,6 +11,7 @@ namespace Kabano;
**********************************************************/
require_once($config['third_folder']."Md/MarkdownExtra.inc.php");
require_once($config['includes_folder']."database.php");
class Comment
{
@@ -34,8 +35,7 @@ class Comment
public function checkID($id) {
global $config;
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");
$con = sql_connect();
$query = "SELECT * FROM content_comments WHERE id=$1";
@@ -78,8 +78,7 @@ class Comment
public function insert() {
global $config;
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");
$con = sql_connect();
$query = "INSERT INTO content_comments (version, creation_date, update_date, author, is_public, is_archive, content, comment, locale) VALUES
('0', $1, $2, $3, TRUE, FALSE, $4, $5, $6) RETURNING id";
@@ -101,8 +100,7 @@ class Comment
global $config;
global $user;
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");
$con = sql_connect();
$query = "UPDATE content_comments SET is_public = FALSE WHERE id = $1";
@@ -126,8 +124,7 @@ class Comment
global $config;
global $user;
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");
$con = sql_connect();
$query = "UPDATE content_comments SET is_public = TRUE WHERE id = $1";
@@ -180,8 +177,7 @@ class Comments
public function listComments($id, $archive=0) {
global $config;
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");
$con = sql_connect();
$query = "SELECT * FROM content_comments WHERE content = $1 ";
if ($archive == 0)
@@ -205,4 +201,4 @@ class Comments
}
}
?>
?>