php const
<?php
define('CONSTANT', 'Hello world !');
const CONSTANT = 'Hello world !';
const NEW_CONSTANT = CONSTANT.' And beyond...';
const ANIMALS = array('dog', 'cat', 'ant');
define('ANIMALS', array('dog', 'cat', 'ant'));
?>
php const
<?php
define('CONSTANT', 'Hello world !');
const CONSTANT = 'Hello world !';
const NEW_CONSTANT = CONSTANT.' And beyond...';
const ANIMALS = array('dog', 'cat', 'ant');
define('ANIMALS', array('dog', 'cat', 'ant'));
?>
php constant name with variable
echo constant($constant_name);
php define constant
<?php
define("GREETING", "Constant value ");
echo GREETING;
?>
php constant
<?php
define("PI",3.14);
echo PI;
echo constant("PI");
?>
PHP constant
class Human {
const TYPE_MALE = 'm';
const TYPE_FEMALE = 'f';
const TYPE_UNKNOWN = 'u'; // When user didn't select his gender
.............
}
how to store connection object in the constant in php
<?php
include_once('IConnectInfo.php');
class Database implements IConnectInfo
{
private static $instance = null;
private $conn;
private $server = IConnectInfo::HOST;
private $currentDB = IConnectInfo::DBNAME;
private $user = IConnectInfo::UNAME;
private $pass = IConnectInfo::PW;
private function __construct()
{
try {
$this->conn = new PDO("mysql:host=$this->server;dbname=$this->currentDB", $this->user, $this->pass
);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->conn->exec('set names utf8');
echo $this->server . " connected successfully" . PHP_EOL;
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
die;
}
}
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new Database();
}
return self::$instance;
}
public function getConnection()
{
return $this->conn;
}
public function getSelectQueryResult($query = '')
{
try {
$query = $this->conn->prepare($query);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo $query . "<br>" . $e->getMessage();
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us