Note that there are some explanatory texts on larger screens.

plurals
  1. POPDO: Why does this cause an error?
    primarykey
    data
    text
    <p>I dont understand why appear this error when create a object like this:</p> <p>The error is in index.php in this line: </p> <pre><code>$dbPerfiles = new DB_Functions(); </code></pre> <p>And the error is this:</p> <pre><code>PDO Connection error: invalid data source name </code></pre> <p><strong>config.php</strong></p> <pre><code>&lt;?php define ("DB_USER","root"); define ("DB_PASS","root"); define ("DNS","mysql:host=localhost;dbname=example"); ?&gt; </code></pre> <p><strong>DB_Connect.php</strong></p> <pre><code>&lt;?php require_once 'config.php'; class DB_Connect { private static $_instance; //Connecting to database public function &amp;pdo_connect() { if(!self::$_instance) { try{ self::$_instance = new PDO(DNS,DB_USER, DB_PASS); self::$_instance-&gt;setAttribute(PDO::ATTR_PERSISTENT, true); self::$_instance-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $ex) { die("PDO Connection error: ".$ex-&gt;getMessage()."&lt;br/&gt;"); } } return self::$_instance; } private function __construct() { } private function __clone() { } } ?&gt; </code></pre> <p><strong>DB_Functions.php</strong></p> <pre><code>&lt;?php session_start(); require_once 'DB_Connect.php'; class DB_Functions extends DB_Connect{ private $dbConnect = ""; public function __construct() { $this-&gt;dbConnect = $this-&gt;pdo_connect(); } public function __destruct() { $this-&gt;dbConnect = null; } public function getDetails() { try { //sql statement } catch (PDOException $e) { echo "Error: ".$e-&gt;getMessage()."&lt;br/&gt;"; return false; } } } ?&gt; </code></pre> <p><strong>index.php</strong></p> <pre><code>&lt;?php session_start(); $max_time = 1800; $current = time(); if(!isset($_SESSION['clientmac']['un']) ) { $_SESSION['clientmac']['un'] == ""; header('Location: index.php'); } else { if (!isset($_SESSION['timeLogin'])){ $_SESSION['clientmac']['tl'] = time(); } else { $session_life = $current - $_SESSION['clientmac']['tl']; if ($session_life &gt; $max_time) { header('Location: include/logout.php'); } else { $_SESSION['clientmac']['tl'] = time(); } } require_once 'include/DB_Functions.php'; $dbPerfiles = new DB_Functions(); //With this line shows the error //code to connect to getDetails() function in DB_Functions.php and //retrieve some data. ?&gt; &lt;!doctype html&gt; &lt;html lang=en&gt; &lt;!-- CODE HTML --&gt; &lt;/html&gt; &lt;?php } ?&gt; </code></pre> <p>I want connect to DB_Functions and connect with getDetails() function or other function in this file and retrieve data.. only that!</p> <p>I hope I have explained.</p> <p>Regards!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload