Jump to content

kenoli

New Members
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About kenoli

  • Rank
    Newbie

Profile Information

  • Gender
    Not Telling
  1. Strider64 -- A couple of questions: 1. I presume "use PDO" is the implementation of the recommendations use a 'use' statement for core classes. Is there any other meaning involved? This doesn't imply the explicit use of namespaces in the project? 2. Regarding 'getConnection(): PDO', I presume this creates security that the output will be a PDO type. I suppose there is no need to use 'declare(strict_types=1)' here because php can't change a return to a PDO type if it is not already a PDO type. Is my understanding of these elements correct? I like your returning the conn
  2. Thanks for the great responses. They are hugely helpful. --Kenoli
  3. benanamen -- I just looked this up and discovered a new feature of php Return Type Declarations. It looks like this is what you are using and it is the perfect answer to my question. I think I can easily apply that to my code and implement some of the code in your approach to my advantage. I will report back how that goes. Thanks, --Kenoli
  4. benanamen -- You didn't do anything much different than I; you just organized your classes differently. What I am seeing is that you are passing the connection from Connection.php to DB.php as an attribute to the __construct method. The makes sense, though I still don't understand how the connection is transferred to the pdo attribute. Perhaps it is the following syntax which I am not familiar with in the connection.php file:: connect(array $config): PDO { ...rest of code} I'm not familiar with the " : PDO" part of that syntax. Can you explain that for me? I appreciate the assis
  5. I created a database class to connect to a database. The code is below. I'm not sure how to call this connection in other classes. Do I use: $db->pdo = $conn->prepare($sql); or what? Note that the db object is instantiated at the end of the class file. Here is the class: class DB { public $pdo = ''; //public $message = 'A message from db'; // Debug function __construct() { // Database info located elsewhere $servername = "localhost"; $username = "root"; $password = ""; $dbname = "dbname"; try { $this->pdo = new PDO("mysql:host=$servername
  6. Barand -- Many thanks. That did it. I just had to change my last function. I should have known that. I was barking up another tree. --Kenoli
  7. I'm trying to create a script to use PDO prepared statements to enter data from a post form using functions to perform the PDO required statements. But, it's not working. When I execute it, it enters null in all the fields. I'm hoping someone can tell me why this is not working. I think the functions output what PDO is looking for. I'm not sure how to do this otherwise without writing a lot of code like $site_name= $_POST['site_name']; and entering all of that in the PDO statments. It seemed like it made sense to create the statements from the post array. My co
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.