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 8857051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:29:59+00:00 2026-06-14T14:29:59+00:00

I’m [finally] learning PDO, and I’ve been dealing for the past hour with a

  • 0

I’m [finally] learning PDO, and I’ve been dealing for the past hour with a problem that I cannot seem to solve. I have this code:

//Simple script that connects to mysql and database.
$db = new PDO ("mysql:host=".Configuration::get('MysqlServername').";dbname=".Configuration::get('MysqlDatabase').";charset=UTF-8",
          Configuration::get('MysqlUsername'),
          Configuration::get('MysqlPassword')) or die ("Error connecting");

// To test why it doesn't work
$STH = $db->prepare("INSERT INTO htranslations (keyword, en, page, last) VALUES (?, ?, ?, NOW())") or die ("Error preparing");
$STH->bindValue(1, "New_test", PDO::PARAM_STR) or die ("Error binding 1");
$STH->bindValue(2, "New test", PDO::PARAM_STR) or die ("Error binding 2");
$STH->bindValue(3, $_SERVER['PHP_SELF'], PDO::PARAM_STR) or die ("Error binding 3");
$STH->execute() or die ("Error executing");

Note: The or die are set only as a temporary measure to test where the error is originated. This code is simply not working, and I cannot figure out why. Now, what I’ve tried:

  • When doing var_dump($db);, I get object(PDO)#1 (0) { } on my browser. I guess this is NOT what it’s supposed to be, but I have no idea and couldn’t find much online. The or die statement not being executed makes me think that this might be right.

  • The error displayed is Error executing. This means that the last query couldn’t be executed, but that doesn’t help much since it could be a problem originated previously.

  • The Configuration class is returning the right values. It was working previously with mysql and I tested it to see if it returned the right values (it does).

  • I’m in 000webhost.com free account. From this forum post and this other there shouldn’t be any problem with the PDO here. Furthermore, print_r(PDO::getAvailableDrivers()); returns mysql, sqlite and sqlite2.

  • The other way around, inserting the values in an array in the execute() statement, doesn’t work either.

The working previous mysql_* code was (it was escaped previously):

 $sql="INSERT INTO htranslations (keyword, en, page, last) VALUES ('$Id', '$Text', '".$_SERVER['PHP_SELF']."', now())";
 mysql_query($sql);

Can you see what I’m doing wrong? If not, can you at least point me in some direction to keep testing it? I followed mainly (but not only) this tutorial. Thank you so much.

  • 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-06-14T14:30:00+00:00Added an answer on June 14, 2026 at 2:30 pm

    Thanks to the user andrewsi I could solve my problem.

    Basically, I had no idea where to look for mistakes, so I run this code var_dump($STH->ErrorInfo()); to find out what was the problem and then fix it. My resulting code was:

    //Simple script that connects to mysql and database.
    $db = new PDO ("mysql:host=".Configuration::get('MysqlServername').";dbname=".Configuration::get('MysqlDatabase').";charset=UTF-8",
              Configuration::get('MysqlUsername'),
              Configuration::get('MysqlPassword')) or die ("Error connecting");
    
    // To test why it doesn't work
    $STH = $db->prepare("INSERT INTO htranslations (keyword, en, page, last) VALUES (?, ?, ?, NOW())");
    $STH->execute(array("New_test","New test",$_SERVER['PHP_SELF']));
    var_dump($STH->ErrorInfo());
    

    It returned a duplicate key, and that’s when I realized that the code that worked (once) with old mysql_* didn’t work here only because of a mistake in the database.

    But I learned how to check out errors in the PDO way (well, still need the try/catch block) and hope that someone coming to this question with a similar error will solve it with this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

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.