Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Hello everyone, :happy:

    I want to use PDO to connect and write to my database table because I've heard of how much more secure PDO is vs. MySQL (which is being phased out and replaced by new systems like NoSQL). In the database writer script that I am using for my website to write new user sign-ups to the table, my PDO connection is failing to make a connection.

    I spoke with the web host's support. They told me that I have all the right credentials (host URL, dbname, user, password), but they told me that the problem is with my script. They tested the connection using MySQLi in a new file that they placed in my directory (code posted below), and this file was successfully able to connect.

    I checked phpMyAdmin and saw that I have all privileges needed to do what I need to.

    Here's my script (parameters are passed in from another file, confirmform.php):
    PHP Code:
    <?php
        
    class DatabaseWriter
        
    {
            public function 
    writeUserToDatabase($email $name $age $gender $country $category)
            {
                
    $host '*************';
                
    $dbname 'emailcollection';
                
    $user '************';
                
    $password '*************';
                
                try {
                    
    $connection = new PDO("mysql:host=" $host ";dbname=" $dbname$user$pass);
                    
    $connection -> setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION); 
                    
    $statement $connection -> prepare("INSERT INTO emailcollection (email, name, age, gender, country, category) VALUES (:email, :name, :age, :gender, :country, :category)");
                    
    $statement -> bindParam(':email'$email);
                    
    $statement -> bindParam(':name'$name);
                    
    $statement -> bindParam(':age'$age);
                    
    $statement -> bindParam(':gender'$gender);
                    
    $statement -> bindParam(':country'$country);
                    
    $statement -> bindParam(':category'$category);
                    
    $statement -> execute();
                
                    
    $connection NULL;
                }catch (
    PDOException $e){
                    echo 
    $e -> getMessage();
                }
            }
        }
    ?>
    The error returned into the console from the above script is as follows:


    SQLSTATE[28000] [1045] Access denied for user 'worldreviewgroup'@'cgi2202.int.bizland.net' (using password: NO)
    This is the other script that seems to work:
    PHP Code:

    <?php
     
    $dbhost 
    "**********";
    $dbusername "**********";
    $dbpassword "************";
    $database "emailcollection";
    $connection = new mysqli($dbhost,$dbusername,$dbpassword,$database) or die("Could not connect to DB");
    if(
    mysqli_connect_errno())
    {
     
    printf("Connect failed: %s\n"mysqli_connect_error());
         exit();
    }
    else
    {
      echo 
    "Successfully Connected to the Database<br><br>";
    }
     
    ?>
    This is my website

    I will really appreciate it if someone can point me in the right direction! :help:

  2.  

  3. #2
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Well, obviously two password variables were causing an issue. $password had the data while $pass was undefined.

    I have amended my code to this:
    PHP Code:
    <?php
        
    class DatabaseWriter
        
    {
            public function 
    writeUserToDatabase($email $name $age $gender $country $category)
            {    
                
    $host '*************';
                
    $dbname 'emailcollection';
                
    $user '*************';
                
    $pass '*************';
                
    $jointime '2013-01-07 11:19:08';
                
                try {
                    
    $connection = new PDO("mysql:host=" $host ";dbname=" $dbname$user$pass);
                    
    $connection -> setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION); 
                    
    $statement $connection -> prepare("INSERT INTO emailcollection (emailaddress, name, age, gender, country, category, jointime) VALUES (:emailaddress, :name, :age, :gender, :country, :category, :jointime)");
                    
    $statement -> bindValue(':email'$email);
                    
    $statement -> bindValue(':name'$name);
                    
    $statement -> bindValue(':age'$age);
                    
    $statement -> bindValue(':gender'$gender);
                    
    $statement -> bindValue(':country'$country);
                    
    $statement -> bindValue(':category'$category);
                    
    $statement -> bindValue(':jointime'$jointime);
                    
    $statement -> execute();
                
                    
    $connection NULL;
                }catch (
    PDOException $e){
                    echo 
    $e -> getMessage();
                }
            }
        }
    ?>
    The output now is:
    SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
    I added in $jointime to match the exact number of columns in the table (trying to put in a timestamp when the user is written to the table), but no luck.

    I hope someone is out there!

  4. #3
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Well, I think this is my last post here. These forums seem to not be very helpful, at least not anymore. oo:

    It is help free of charge, but it's been not much help here at all.

    I'll try to help others on my way out the door, but this is gonna be it for me at WDF.net. :bye:

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    I only have these comments ...

    I didn't know the answer to your original post, so that's why I didn't post anything.

    You are correct that you should be using MySQLi (as opposed to MySQL).

    You are partially correct that nobody seems to care. Since WDF got new owners a year or two ago, there has been sort of a lack of direction and control over the background operations. Several key people have since not been around, and traffic has declined.

    That being said, this could be an opportunity for you to actually jump-in and really provide help for the topic of this thread. Everyone involved with PHP needs to be doing the transition to MySQLi, and we (.. meaning myself as well as many others) are not so well up-to-speed on that.

    Do you have any idea how much your posts on this thread have helped others? Even though you didn't get any responses?


  6. #5
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Well, I was elated to find that the only thing wrong here was that the query was using a reference to the correct column name, :emailaddress, while the bindValue() was using :email

    Case closed. Thank you for the response anyway.

  7. #6
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Quote Originally Posted by Tyler Smith, post: 249426
    Well, I think this is my last post here. These forums seem to not be very helpful, at least not anymore. oo:

    It is help free of charge, but it's been not much help here at all.
    I'll try to help others on my way out the door, but this is gonna be it for me at WDF.net. :bye:
    I'd like to add this - I read the post, and did not answer because I did not know how, and I believe that simply posting "sorry, Dude, can't help ya" is a waste of your time when you see that there's a response and then find it is a meaningless one.

    You are ready to give up on the forums after waiting less than 48 hours for a response. These are, after all, forums, and not chat rooms - and it could just be that on the long Easter weekend not many people check in. Also, it is a difficult question, and out of those that do check in,it's quite possible there was nobody who knew how to answer it.

    In any case, thanks for sharing your fix - it may well help someone else, as many of your other posts have, even if you're not interested in participating anymore. :bye:
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  8. #7
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Really, I should just say thanks for what you guys do for me. I'll still be hangin' around and trying to help others, too.

    This post I made here is just hasty. Even though I'm in a rough spot and time is of the essence, I think I can find a more productive way to deal with my anxieties.

    I am a member at a few different web development forums, and it just seems like I oftentimes get more valuable feedback on those boards. Although, WDF.net has helped out before any others in some instances.

    WebDesignForums.net still has my support.

    I find myself becoming addicted to web dev. forums as I learn so much and get so much out of them (even though I'm still a bit of a newbie and can't help others in the best way sometimes), so who am I to bash a perfectly good community of web developers?

    Maybe you will want to delete my posts except for the solution. I will hate to see this create some bad fuzz about these great message boards.

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    I don't want to delete any of those posts because the site owners need to see that this forum needs some tender loving care. Your experiences are not yours alone. A website is never "finished" ... it takes continuous development, improvements, advertising, and excitement to draw new users.

    But I digress back to the PDO MySQLi topic. I also need to start using MySQLi, even though MySQL will still be valid until it finally deprecates. I'm just not sure if my webhost supports the PDO part of it ... and where that all fits together. I will have to start reading-up on this topic and want to know more about where you're finding information about this.


  10. #9
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Here is a fairly decent article that discusses why PDO seems to be the best choice. I can't imagine your web host not supporting PDO because it seems be nothing more than a PHP class.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

mad smith pdo

Click on a term to search for related topics.
All times are GMT -6. The time now is 10:42 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com