Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6330917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:57:34+00:00 2026-05-24T17:57:34+00:00

this here below is my class database in php <?php class DB { private

  • 0

this here below is my class database in php

<?php
class DB
{

    private $SQLcommand;
    private $bd;

    public function setSQLcommand($valor)
    {
        $this->SQLcommand = $valor;
    }
    public function getSQLcommand()
    {
        return($this->SQLcommand);
    }

    function __construct()
    {
        $this->bd = new PDO("mysql:host=localhost;dbname=cpd", "root", "");

    }
    public function ExecSQL()
    {
        if ($this->SQLcommand != "")
            return($this->bd->exec($this->SQLcommand));
        else
            return(false);
    }   
    public function ExecSelect()
    {
        if ($this->SQLcommand != "")
        {
            $data = $this->bd->query($this->SQLcommand);
            return($data->fetchAll());


        }
        else
            return(false);
    }
    function __destruct()
    {
        $this->bd = null;
    }

}
?>

and here is how I instantiate

include_once 'db_class.php';

$e = new DB();
$e->setSQLcommand("INSERT INTO characteristic (id_charac,name_charac)
                VALUES ('','".$_POST["nomecharac"]."')");
$e->ExecSQL();


$p = new DB();
$p->setSQLcommand("select * from characteristic");                  
$data = $p->ExecSelect();

I would ask where in the code I can I put a try catch, that if an error occurs the try catch redirects to the file maintenance.php, and prevent the bank’s User and password are showed…thank you all…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:57:35+00:00Added an answer on May 24, 2026 at 5:57 pm

    You can put in your constructor __construct()

    try {
        $this->bd = new PDO("mysql:host=localhost;dbname=cpd", "root", "");
    } catch (PDOException $e) {
        die('Database connection could not be established.');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP mysql database I have created a follow on question to this one here
I've got this code here: SqlCommand CodeStatus = new SqlCommand(SQL, DB); DB.Open(); Reader =
I'm using the source code found on this site here: http://webtint.net/tutorials/5-star-rating-system-in-php-mysql-and-jquery/comment-page-1/#comment-2562 A fantastic resource,
Jeff Atwood wrote about this here , and while I understand the theoretical performance
I've posted this here , but thought it might deserve a question on its
I realize there is a somewhat related thread on this here: Loading assemblies and
I'm perhaps being a bit lazy asking this here, but I'm just getting started
This article here suggests to use -XX:+UseParNewGC To enable a parallel young generation GC
I've seen this questions here . I'm wondering if there exists an official name
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.