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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:14:18+00:00 2026-06-14T13:14:18+00:00

Inserting data into database with pdo prepared statment, doesnt work for me: I use

  • 0

Inserting data into database with pdo prepared statment, doesnt work for me:

I use this function:

    public function get_number_of_matches(){
     $stmt = $this->pdo->prepare("INSERT INTO `words`( `word_name`, `word_count`, `search_id`) VALUES (:word, :count,:searchID)");
       $stmt->bindParam(':word', $word);
       $stmt->bindParam(':count', $count);
       $stmt->bindParam(':searchID', $search_id);
   for($i=0;$i<count($this->words);$i++){
     if(preg_match_all('/'.$this->words[$i].'/i', $this->text,$matches)){
       $count=count($matches[0]);
       $word=$this->words[$i];
        $search_id=1;
       $stmt->execute();
         break;
    }   

   }
    return 0;
}

Basically, I try to loop over the values and put them into the database.. no error is given.. nothing goes into the database ..why?

This is how I connect to the database:

 class DBConnection {
    public static $connect;

    public static function connect(){

        if(!isset(self::$connect)){
            try{
              self::$connect=new PDO('mysql:host=localhost;dbname=tweeter', 'root', '');
            }catch(Exception $ex){
               echo $ex->getMessage();   
            }
        }
        return self::$connect;
    }
}

UPDATE
Also..see here:

I do the same thing with a different query..but when I try to put object properties inside a variable I get an error:

$tweet= $tweet->tweet ;
$user=$tweet->tweeter_name;
$link= $tweet->link;

Those variables go into a query:

       $pdo=  DBConnection::connect();
    $stmt = $pdo->prepare("INSERT INTO `tweets`( `tweet`, `tweeter_name`, `link`, `date`, `search_id`) VALUES (:tweet, :tweeter_name, :link, :date, :search_id)");
      $stmt->bindParam(':tweet', $tweet);
       $stmt->bindParam(':tweeter_name', $user);
       $stmt->bindParam(':link', $link);
       $stmt->bindParam(':date', $date);
       $stmt->bindParam(':search_id', $search_id);

I get errors like this:

Notice: Trying to get property of non-object in C:\xampp\htdocs\Twitter\demo.php on line 36

Notice: Trying to get property of non-object in C:\xampp\htdocs\Twitter\demo.php on line 37

Notice: Trying to get property of non-object in C:\xampp\htdocs\Twitter\demo.php on line 38

I can print the properties..but when allocating them to those binded variables..the above errors crop up

I get also this:

Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘tweeter_name’ cannot be null’ in C:\xampp\htdocs\Twitter\demo.php:40 Stack trace: #0 C:\xampp\htdocs\Twitter\demo.php(40): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\Twitter\demo.php on line 40

I checked instead like this:

    $tweet= "111111"; // $tweet->tweet ;
        $user= "22222222"; // $tweet->tweeter_name;
        $link= "3333333";  // $tweet->link;
        $date= "444444";

and it worked..for some reason it hates those object properties ?!?

This should go as input:

RT @OrganicLiveFood: Scientists Warn #EPA Over #Monsanto’s #GMO Crop Failures & Dangers #prop37 #labelGMO #yeson37 http://t.co/2XhuVxO8
Doumastic
TweetCaster for iOS
Mon, 19 Nov 2012 20:40:55 +0000
RT @OrganicLiveFood: Scientists Warn #EPA Over #Monsanto’s #GMO Crop Failures & Dangers #prop37 #labelGMO #yeson37 http://t.co/2XhuVxO8

But it doesnt…?!?

  • 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-14T13:14:20+00:00Added an answer on June 14, 2026 at 1:14 pm

    Add self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); right after connecting.

    It would make sure PDO will throw PDOExceptions on every error, making them very easy to see. The error would then outline exactly what’s wrong.

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

Sidebar

Related Questions

I have following code for inserting data into database using PDO. It inserts data
I am using mysql_real_escape_string function while inserting the data into MySQL database. I am
I am inserting data into my database using the following code: $this->db->set('event_id', $event_id); ...
In my c# application i am inserting data into sqlite database as below String
I am inserting a lot of data into a RavenDB database; about 2 500
Getting error while inserting values into database (SQL Server 2008) Implicit conversion from data
I'm experiencing a problem inserting values into a SQLite database. The data I download
I am inserting data into a mySQL database, but I am inserting banking details
I have created some form for inserting data into database and for checking if
I am getting an error while inserting data into a database. The error is:

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.