Questions tagged [pdo]

PDO, also known as PHP Data Objects, serves as an exceptional data-access abstraction layer or interface specifically designed for PHP. This remarkable tool collaborates seamlessly with the majority of renowned database systems available today.

Converting Mysqli to PDO for PHP and Ajax Infinite Scroll functionality

Currently, I am in the process of converting my Mysqli code to PDO for an Ajax infinite scroll system that I came across on the internet. My goal is to integrate this into the blog project I am working on to enhance my understanding of PHP. if( isset($_PO ...

Why is my data not updating in the database with PDO?

I'm currently facing an issue with updating my database using PDO. While I can easily select data without any problems, the update function just doesn't seem to work. There are no error messages displayed, but after running the query, there are no changes ...

The PHP PDO prepares a query but fails to execute it

I am completely new to utilizing php and pdos. A close associate of mine has actually put together a pdo class along with a few examples detailing how it can be employed, and so far, everything has been running smoothly for me. However, I have encountered ...

What is the process for retrieving data from a database using PDO?

Currently exploring PHP and enhancing my skills. <?php // Establishing a connection with the database $dbhost = "localhost"; $dbname = "pdo"; $dbuser = "root"; $dbpass = "7777777"; $conn = new PDO("mysql:host=$dbhost;dbname=$dbn ...

AJAX request experiences significant delays due to MySQL query execution

The issue There is a significant delay in the execution of AJAX requests that involve any database queries. This problem has suddenly emerged without any recent updates to the codebase. Interestingly, if the same query is executed on a webpage directly (e ...

Preventing duplicate values in arrays using PDO

I am currently working on retrieving currency ids from a database using the following code: $arr = []; $currency_codes = array("USD", "RUB"); $currency_codes_in = implode(',', array_fill(0, count($currency_codes), '?')); $query = "SELECT `curr_id` FROM ` ...

Escaping single quotes within parameters of PDO prepared statements

It seems that using PDO Prepared Statements protects against SQL injection and ' escapes. I recently tested the following code... if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["id"])) { $id = $_POST["id"]; //$id = "2&ap ...

Perform a fulltext search using PDO to retrieve results based on partial matches of keywords within a database column

I'm attempting to search two columns in a database with this small PDO statement: $search = $pdo->prepare(" SELECT * FROM books WHERE MATCH (title, author) AGAINST (? IN BOOLEAN MODE); "); $search->execute(array('*' . $_POST['search'] . '*')); ...

The error exception in Laravel 5.0 is throwing a message about an undefined property

I'm encountering an issue with SQL in Laravel within a controller. Below is my code snippet: public function getKeyword() { $date = strftime("%Y-%m-%d"); echo ($date); $keyword = DB::table('demo_question_keyword') ...

What advantages does using bindparam have over execute, especially when dealing with integers in the context of the execute method?

After starting to use PDO, I noticed that even though when I bind param I can define the type of value being sent, my queries always seem to work fine when sending them as strings via execute. So, I'm trying to understand the purpose (which exists, I just ...

The PHP function PDO::lastInsertId() along with the constant ATTR_PERSISTENT provide a

I am facing a similar question to the one discussed here. From what I gathered from that discussion, it seems that PDO::lastInsertId() is secure when called from different connections. However, does this imply that using PDO::ATTR_PERSISTENT => true in ...

Using the power of PDO, implementing variable SQL query with bindParam and executing it within

After making the switch from using mysql_ functions to PDO, I've encountered a bit of a challenge that I'm hoping to get some help with. The issue I'm facing is with the search query. Currently, I have it set up like this: $result = $DB->prepare('SELE ...

PHP script using SQL SELECT query to retrieve records with dates greater than a specified value, including dynamic PHP variables

After reading through various threads on this issue, I still haven't found a solution that incorporates php variables. I am trying to retrieve the first 100 new records after a specific date from my database, but I'm struggling to make it work. ...

Experiencing Setbacks while Implementing AJAX in a PHP Object Orient

I'm currently attempting to create an object-oriented programming (OOP) login system using Ajax. However, I am encountering issues with starting the session or being redirected to the "Directivo.php" page. When I run the code, there is no output displayed. ...

Is there a risk of collision when using PDO and mysqli at the same time?

Currently, our main database connection is using mysqli. However, we are considering transitioning to Doctrine DBAL, which is built on top of PDO, a more flexible database abstraction layer. The game plan is to gradually shift from mysqli to DBAL while re ...

Duplication issue with PDO object rows being printed twice

Having an issue with my web interface design for a database where values from a query are getting duplicated because 2 indices are counting the same value. Any ideas on why this might be happening? Here is the PHP code snippet: function loadTable() { ...

Saving information from MySQL database into a CSV file using PDO through a web browser

I'm struggling with a form that writes data to a MySQL database. My goal is to allow users to download their submitted data in CSV format once they complete the form. Currently, my code is displaying the database contents on the browser instead of ge ...

"Optimizing website performance with Ajax and securing data with

As I work on developing an Ajax chat application, I have found the need to periodically call a PHP script that checks for new messages in the database. I recently learned about PDO prepared statements and thought they could be useful since only one variab ...

Issues With Functionalities

I'm currently working on a script that calculates page load time using functions. I am particularly interested in utilizing PDO for inserting data into a database. Homepage <?php require 'common.php'; require 'page_load_statistics.php'; page_load_sta ...

Ways to increment a database field value by 1 when refreshing using PDO

I've been searching for an answer to this question, but unfortunately no one has been able to solve my problem. My query is about increasing a database field value. Here's the issue: when I refresh the page for the first time, it automatically ad ...

Assistance required to enhance PHP search functionality

Looking to develop a PHP search engine that can filter search results by time, like Google's refine search feature. The twist is using a select dropdown instead of a submit button. Using SQL Server as the database with pdo-sqlsrv driver. Regular searc ...

Sending data from the client side using AJAX and PHP to the server

Struggling with using AJAX to send values over to a PHP file for updating a MySQL database on the server. However, I've encountered an issue where the values don't seem to be properly transferred to the PHP file. This is the JavaScript code I am currently ...

The JSON data is being posted, but the table remains empty and does not populate

UPDATE: Tried modifying the Jquery code to dynamically recreate rows, but it still doesn't work Reorganized my table structure with no success I have a PHP script that encodes my database table into an array. When I echo the json_encode, everything ...

Unable to add data to MySQL database via PDO without receiving any errors

I've encountered an issue with inserting data into a MySQL database using PDO. Despite not receiving any errors, the table remains empty whenever I try to check if a row has been successfully inserted. Although I can connect to the database and perf ...

PdoServiceProvider not found in Dokku-deployed Silex deployment

After encountering random crashes with socket errors while using the abandoned herrera-io/silex-pdo PDO provider in my Silex project, I switched to csanquer/pdo-service-provider. Everything worked perfectly on my localhost server, but upon deployment to a ...

I am attempting to establish a connection to a database using PDO within the CodeIgniter framework

$database_config = array( 'hostname' => 'mysql:host=myhostname;dbname=test;', 'username' => 'root', 'password' => '', 'database' => 'test', 'dbdriver' => 'pdo' ); Error Message: PDO::__construct(): php_network_getaddress ...

Issue with PHP PDO bindParam not correctly handling array data

A mechanism has been created to enable users to determine the order in which products are displayed within a product group. This mechanism relies on a database table named "grouplines" (MySQL) with columns for group_id, product_id, and manual_order. The fi ...

I am hoping to transmit an array from a function using Ajax and JSON

Having trouble sending a JSON array from a function. This is my code: function categoryTree($parent_id = 0, $sub_mark = ''){ global $connection; $query = 'SELECT * FROM ws_categories WHERE parent_id = :parent_id ORDER BY sort_order ASC, name ASC' ...

Improving database values by adding a constant to them and updating them using PDO

Here is the situation: I am trying to create a system that updates a value (by adding 1 to the current value) stored in a database for a specific user who logs into the website. Below is the code I have been using: $value = $row["value"]; $add_value = $db ...

Combining the contents of two array tables

I am attempting to retrieve the status of all users from my website. Here is my table https://i.stack.imgur.com/2I3xi.png When another user adds me, their username is added to user1. If I add another user, my username gets added into user1 and theirs into ...

The absence of character encoding is evident at a specific location

I'm attempting to input data into a mysql database. This data often includes German umlauts. This is the method I am using: function insertMenu($content, $date) { $session = $_SESSION['aid']; global $pdo; $pdo->exec('SET CHARACTER SET utf8 ...

Error: Database connection error occurred due to missing default value for field 'id' (PDOException in Connection.php line 358) (SQLSTATE[HY000]: General error: 1364 Field 'id' doesn

I've exhausted countless methods to troubleshoot this issue, but nothing seems to be effective. How can I resolve it? I've attempted the following steps: -setting auto increment for table. -reinstalling php laravel, re-installing and verifying all PHP conf ...

Incorporating a WHERE clause into the COUNT query

Having some difficulty incorporating a where clause into a COUNT query. The following code successfully retrieves the total count of the table: $search = $_POST['search_text']; SELECT COUNT(*) FROM stories') ->fetchColumn(); However, when attempti ...

Using PDO to retrieve data from a mysql database table stored in innodb format, the query fails if the field values contain apostrophes

Utilizing prepared queries and binding variables to placeholders has been effective for inserting data without issues. However, a concern arose when the registration form received a value like St. John's in a field. The data was successfully written, ...

Adding a post with several tags using PDO

Database Structure: Table: posts Columns: postid, postsubject, contents Table: tags Columns: tagid, tagtxt Table: posts_tags Columns: postid, tagid //I have already added the posts and retrieved the last id which is stored in $newId Insert into tags t ...

Add several rows to the transactions table, and in case one insertion fails, allow the remaining rows to be added

I am working on an application that extracts hotel names and addresses from various websites. My challenge is inserting this data in batches of 10 into a MySQL database. If any insert fails (for example, if the hotel name exceeds 100 characters while the ...

What could be causing the multifiles uploader to fail in uploading files?

I have been attempting to create a multiple files uploader with sorter connected to a database on my website. However, whenever I try to upload some files, the uploader sends me several notices. Notice: Undefined index: media in /var/www/mediasorter/mediau ...

PHP is encountering difficulties when attempting to fetch extensive requests

I have developed a PHP service that retrieves JSON data from a table consisting of 2100 rows. My development setup includes: Xampp with Apache and MySQL Windows 10 PHP-7.0.8 I am using PDO in PHP to execute the query. The service used to function flawl ...

Move data from one mysql table to another in different databases using PDO

After spending the last hour researching, I still haven't found a straightforward solution that doesn't involve complicated exports and imports. All I want to do is establish a PDO connection with two databases so that I can utilize them both in ...

Insert data into a database using PDO from a dynamic HTML table structure

Having recently started working with PHP, I've encountered a challenge with creating a dynamic HTML table. I managed to get the table functioning correctly and successfully inserted values into a MySQL database. However, I'm struggling to underst ...

"Engaging in a wild goose chase by fetching multiple results even though only one

Having some difficulty with this code lately. Everything is running smoothly except for the Tax query, which seems to be causing issues due to multiple TUID and UID values that are not mapping correctly (e.g., ID 1 could represent either User1 or Group1). ...

PHP PDO prepared statement with SELECT query for insertion

This task is quite challenging for me. I've prepared the following "insert into" statement for Postgres using PHP PDO. $sql = "INSERT INTO mytable (zuordnung_id,spielgen_id,spielvor_id) VALUES ( :zuordnung_id, ...

A step-by-step guide on integrating PDO with CodeIgniter version 3

While using Codeigniter, I encounter an issue where it only displays "loaded" after the execution, but the table remains empty when attempting to run it with PDO: function loadCSVtoDB($csvfile){ $stmt = $this->db->conn_id->prepare("LOAD DATA ...

PDO SQL Query Not Restricting

After executing a query to the database with LIMIT 10, I'm not getting any results. It seems like there might be an issue with my code. Can anyone spot the mistake? Here's the code snippet that I believe is causing this unexpected behavior. I'd appreciate ...

Database structure does not dictate PDO MySQL querying independence

When using PDO to communicate with a MySQL database and utilizing named placeholders, it is essential to have an understanding of the database structure: $db->("INSERT INTO table (firstname, lastname, age) value (:fn, :ln, :age)"); Is there a method f ...

Enhance and append data to MySQL output

Is it achievable to include a custom key value pair to the existing SQL result? <?php require_once "dbaccess.php"; $json = array(); $access = new DatabaseAccess(); $sql = $access->Connect(); $stmt = $sql->prepare("select * f ...

An issue with calling the fetch_() function on a member in PHP

Having issues with this code snippet: $query = "SELECT * FROM blog"; $posts = $pdo->query($query); $resultaat = $posts->rowCount(); $row = $resultaat->fetch_(PDO::FETCH_ASSOC); if($resultaat > 0){ while ($row){ echo $row['titel']; ...

Transforming the output from fetchAll() into a well-

Currently, I'm utilizing fetchAll(PDO::FETCH_ASSOC) to query my self-made database using an SQL statement. In order to visualize the retrieved data, I am employing print_r(). The values returned by print_r() look like this: Array ( [0] => Array ( [Type ...

Utilizing the chain method in the PDO class

This is a "wrapper" class that utilizes PDO (although it is quite extensive, the important segment is highlighted here) class DB { protected $pdo; protected $dsn; protected $username; protected $password; protec ...

Filtering, cleaning, and confirming the validity of data input allowed for HTML tags

While there is a lot of information available on sanitizing, filtering, and validating forms for simple inputs like email addresses, phone numbers, and addresses, the security of your application ultimately relies on its weakest link. What if your form inc ...

Retrieve data from two tables in PHP and display the table name

My current PHP code is designed to retrieve data from two different tables in MySQL using the UNION statement. $sql=" SELECT 'ticket_updates' as rowTable, sequence, ticket_seq, notes as displaydata, date ...

Having trouble with Codeigniter and Pdo? Getting an error that says "call to a member function

Recently, I upgraded to CodeIgniter 2.2.0 and decided to implement a PDO database connection with the PDO driver. However, I encountered an error that is causing some troubles for me. Can someone help me identify what might be missing in my setup? $active ...

Tap on the child to reveal their parent

I am working with a family tree that includes dropdown menus containing the names of parents and children. Each child has a link, and when I click on a child's link, I want their father to be displayed in the dropdown menu as the selected option. Can ...

Unable to add records to the SQLite database using PHP PDO framework

Could someone please take a look at this code and help me find the issue? (I have already tested the database connection and it seems to be working fine). <?php $user_name=$_POST['user_name']; $password=$_POST['password']; $dbh=new ...

What is the issue with this particular PDO?

So here's the issue - all other PDO queries are working fine, but this one is giving me trouble. I've tried using execute(array(':t'=>$table)); but no luck. Any ideas? public function __construct($table){ try{ $pdocnx = new PDO("mysql:ho ...

"Encountering issue with $.ajax() not accepting PHP array as

I am currently utilizing ajax to fetch data from a table stored in a MySQL database. The ajax calls are being made using jQuery, with the databases being accessed through PDOs. PHP function fetchQuestions() { $database = "answerMe"; // n ...

Retrieving NULL Values using PHP PDO

What is the method to verify if a column's value is null? Here is an example code snippet: $db = DBCxn::getCxn(); $sql = "SELECT exercise_id, author_id, submission, result, submission_time, total_rating_votes, total_rating_values FROM submissions LEFT ...

PHP encountered an issue when retrieving a value from a URL and passing it to a JavaScript variable

How can I pass a PHP variable from the URL using $_REQUEST to JavaScript in order to send it through Ajax? Here is the code snippet at the top of my page: <?php include_once('../php/connection.php'); include_once('../php/getDiagnosis.php'); $pid ...

Having trouble connecting to a recently installed PostgreSQL database through a php script

Having recently transitioned from MySQL to PostgreSQL, I installed PostgreSQL on my Fedora system and set up the postgres user following the instructions on the Fedora wiki. After creating the role using the psql shell while su-ing into the postgres user, ...

How to Save PostgreSql Large Objects to Files Using PHP PDO

This code displays LO to the browser: ... $my_pdo_connect->beginTransaction(); $stream = $my_pdo_connect->pgsqlLOBOpen($oid, 'r'); fpassthru($stream); ... I am facing a challenge in writing the LO to the file system. While I am familiar with pg_lo_ ...

PDO CRU is experiencing technical difficulties

I'm seeking assistance to resolve an issue in my project. I am working on implementing a book reservation feature, and everything seems fine except for the Object-Oriented Programming (OOP) functions that involve PDO statements. Specifically, I'm facing di ...

PDO: Utilizing arrays for data binding in SELECT queries

I am currently working on setting up an array that contains all the necessary parameters for my PDO queries in a separate file. The initial query I am focusing on is a SELECT query that only requires one parameter. $data = array( 'us_id' =&g ...

SQLSTATE[HY093]: The parameter number provided is invalid because the parameter was not defined

Encountering the error mentioned above consistently. The issue arises with my setup depicted below: $InsertSQL = "insert into reports.NonVarassetInvoices(State, CLLI, Type, Vendor, DateReceived, InvoiceNumber, InvoiceDate, TotalInvoiceAmount, ProjectWONum ...

SQL Injection - what more could you ask for?

Recently, I discovered an interesting Firefox addon called 'SQL Inject Me'. To satisfy my curiosity, I decided to test it on a simple phonebook intranet site that has an admin account. The test results showed 51 #302 errors, but despite trying them out, I ...

Transform the parent-child array into an unordered list using list items

Extracting and organizing username (child) and referral (parent) records from the database are done using the following code: $sql = "SELECT username, referral FROM acc_status"; $q = $conn->prepare($sql); $q->execute(array()); ...

Retrieving information from a database using PHP PDO to populate a dropdown list

On my HTML page, I have a form that allows users to insert data into the database. Some fields in the form require dropdown lists, and I want to populate these dropdowns with data from the database. Previously, I had hardcoded the dropdown options like th ...

How often do you want to see just a single row displayed?

I have a situation where I need to compare data between two SQL tables - one containing manually inserted data and the other with data automatically inserted by a script. To ensure that the script is functioning correctly, I want to verify that both table ...

Error: Parameter number is invalid in PDO query

I have implemented the following PDO SQL Query: $stmt = $pdo_conn->prepare("INSERT into ticket_updates (ticket_seq, notes, datetime, updatedby, customer, internal_message) values (:ticket_seq, :notes, :datetime, :updatedby, :customer, :internal_message ...

The HTML head JavaScript files are not applicable to dynamic Bootstrap modals

I have broken down my PHP files into smaller parts, for example, tillbody.php contains everything from the HTML tag to the body tag, followed by navbar.php and so on. I am including these files in index.php. Here is the code for a better understanding: &l ...

Creating a PDO table within another table by utilizing the power of JSON

I am looking to transmit data from 3 tables in my MySQL database using JSON The tables I need to access are: $stmt1 = $db->prepare("SELECT * FROM data WHERE id='1'"); $stmt1->execute(); $result1 = $stmt1->fetch(PDO::FETCH_ASSOC); $stm ...

The error message "PDOException: driver not found" indicates that the driver needed

Whenever I try to connect to a MySQL database on localhost using PHP, I encounter a PDOException stating that the driver could not be found. $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $thi ...

Guide on assigning ownership of a note in the 'notes' table to a user in the 'users' table using PHP and MySQL

Is there a way to assign ownership of a note in the 'notes' table to a user from the 'users' table? For example, how can I make user with id "1" in the 'users' table the owner of the note with id "2" in the 'notes' ...

Troubleshooting Issues with PHP7 and SQL Server Integration on Windows Platform

Encountering a "Fatal error: Invalid handle returned. in" message in PHP 7 when attempting to connect with SQL Server. Tried the following options: Error connecting to MSSQL with SQLSrv and PHP 5.4.7 Unable to connect to SQL Server with PHP The code bei ...

Struggling to construct a binary tree as my descendants are not arranged in the right sequence

I am currently working on building a binary tree using PHP, MySQL, and a jQuery plugin developed by Frank-Mich. Here is the progress I have made so far... DATABASE STRUCTURE CREATE TABLE IF NOT EXISTS `members` ( `id` int(11) NOT NULL AUTO_INCREMENT, ...

PHP PDO Remove records older than user-specified number of days

Recently, I delved into the world of PHP and database management about a month ago. Luckily, most of my issues were resolved through diligent Google searches. Currently, I am working on creating an admin feature that allows for the deletion of entries old ...