public static function getConnection() { if (!self::$_connection) { $dbhost = DATABASE_HOST; $dbuser = DATABASE_USER; $dbpassword = DATABASE_PASS; $dbname = DATABASE_NAME; $dbport = DATABASE_PORT; self::$_connection = @pg_connect("host=" . $dbhost . " port=" . $dbport . " dbname=" . $dbname . " user="******" password=" . $dbpassword); if (!self::$_connection) { throw new Exception('Gagal melalukan koneksi ke database. ' . pg_last_error(self::$_connection)); } } return self::$_connection; }
public static function getConnection() { if (!self::$_connection) { $dbhost = DATABASE_HOST; $dbuser = DATABASE_USER; $dbpassword = DATABASE_PASS; $dbname = DATABASE_NAME; self::$_connection = @mysql_connect($dbhost, $dbuser, $dbpassword); if (!self::$_connection) { throw new Exception('Gagal melalukan koneksi ke database. ' . mysql_error()); } $result = @mysql_select_db($dbname, self::$_connection); if (!$result) { throw new Exception('Koneksi gagal: ' . mysql_error()); } } return self::$_connection; }
function numRowSearchPost($value) { $pisah_kata = explode(" ", $value); $jml_katakan = (int) count($pisah_kata); $jml_kata = $jml_katakan - 1; $sql = "SELECT * FROM " . $this->_tableName . " WHERE "; for ($i = 0; $i <= $jml_kata; $i++) { $sql .= "title OR content LIKE '%{$pisah_kata[$i]}%'"; if ($i < $jml_kata) { $sql .= " OR "; } } $sql .= " AND active='Y' ORDER BY id_post DESC"; $result = mysql_query($sql, PoConnect::getConnection()); $result = mysql_num_rows($result); return $result; }