Questions tagged [pdo]
PDO is a PHP extension that serves as a data access abstraction layer for accessing databases.
337
questions
1
vote
1
answer
88
views
PHP Validation script
The code below is modified slightly from the code in this previous post.
I believe the code below could be improved and more secured but i don't know how so someone please show me how an improved ...
0
votes
1
answer
88
views
SQL & PHP login method
My code is working however it seems to be using old outdated php version so less secure and I'm still new to programming so I'd be more than thankful if someone shows me how an improved updated and ...
2
votes
2
answers
118
views
Best Practices for PHP PDO Pagination with Search Functionality
I'm working on implementing a pagination system with search functionality using PHP and PDO. The code I've written seems to work, but I want to ensure that I'm following best practices and avoiding ...
1
vote
0
answers
47
views
PHP PDO prepared statement with IN [closed]
Here's my code:
...
0
votes
1
answer
172
views
Can I use PDO transaction in this way? [closed]
So I want to use PDO transaction in PHP OOP where in the class are multiple insert/update queries.
If I create a new methods in Class like beginTransaction(), commit(), rollback() and I use them ...
1
vote
1
answer
328
views
Wrap INSERT statements to PDO transaction (PHP OOP)
so Im trying to wrap SQL INSERT statements to PDO transaction in PHP OOP. I don't know if I'm doing it right and this is the best/easiest way to do it.
So what is important for me is:
There can be ...
1
vote
1
answer
236
views
Is this PDO query okay to use in PHP OOP?
Do you think this code is good if I want to do a simple SQL query? Is it safe to use? Or am I doing something wrong?
...
5
votes
3
answers
169
views
DB Class extending PDO w/ other useful functions
I have this DB class that extends PDO, that also has useful functions for certain tasks; I was wondering how well it's coded, and if so, what I could maybe improve on. I tried commenting in ...
3
votes
1
answer
154
views
Proper PDO connection function
I am reviewing the database class for a live website. I am not sure if the current connect function is the best way to create a pdo object as it appears to create a new connection every time it is ...
1
vote
1
answer
73
views
Updating multiple database tables when products are shipped back by customer
So, in this example I have to make these changes in my tables:
Select Product Data => SKU, QTY
Insert into shipping_back table
Update in shipping_back to current date
Update in customers to ...
1
vote
1
answer
67
views
7
votes
2
answers
200
views
Connect to MYSQL database in PHP with prepared statements
I have recently learned about using PDO. I created a db class which could handle common actions like create, update, delete and select. Is this method a correct way to connect to the database using ...
3
votes
1
answer
109
views
Pagination helper class
The most nauseous problem with pagination is the fact that you have to write two almost identical queries. For the various reasons I am not inclined to use the SQL-only way (such as ...
4
votes
2
answers
198
views
Using a transaction to create account records
This is my first time using commit and rollback. I just need to know if this is a proper execution of the functions for this particular situation:
...
4
votes
1
answer
137
views
Storing and confirming user input
I am a beginner, and I'm trying to secure a sign-login system on my website. Is my code good/enough to prevent SQL injection?
THIS IS THE SIGN FILES
This is the index.php that takes user input:
...
1
vote
3
answers
96
views
What is the best way to login according to account type with server-side validation?
I have two access roles as of now for example account_type 1 and 2.
What I am doing is, <...
1
vote
0
answers
259
views
Registration and login via PDO
don't blame me I am trying to learn, the code works but I am not
sure it is well optimized. Please tell me if you see something wrong.
My goal is to achieve most optimized code (and learn something in
...
4
votes
2
answers
430
views
API for SQL queries with PHP PDO
I'm writing a very simple CRUD application, and I'm wondering if the way I'm using static methods throughout the code makes sense. I'd very much like to simplify ...
5
votes
1
answer
389
views
function for PDO queries and return result - tested - any tips?
I write a function using PHP and MySQL, to get PDO connection, query and array of placeholders to execute query and return result.
I test this function and it has good response when result for ...
1
vote
2
answers
119
views
Repeated DB connection at max user connections
I am trying to create class with connect to mysql database. And if there is max number of connections I want to wait and try it again. I figured out, how it can works, but I am not sure, if its the ...
1
vote
0
answers
51
views
Good practice for dB connections
Is it good practice to keep the connection strings for websites in another folder outside of the site folder?
For example, here is the htdocs structure. I am working on site3:
...
3
votes
1
answer
641
views
Sanitizing user form input in php
Security threats in mind:
SQL Injections!!! --- Solutions: Prepared Statements (PDO) and including
$bpdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); in ...
5
votes
2
answers
574
views
Mysql PDO Wrapper that throws Unique Constraint Exception
The main reasoning behind this PDO wrapper, is that I find myself using unique constraints quite frequently in my designs, and I have ...
-4
votes
2
answers
451
views
Is this a good approach to replace mysqli_num_rows? [closed]
Is this a good approach to replace mysqli_num_rows?
$db is a PDO instance. ..
...
8
votes
3
answers
1k
views
How secure is my PHP registration script?
I coded a registration form and was wondering if anyone could give me feedback on whether I'm lacking any major security mechanisms. I've done loads of reading around the topic and feel it should be ...
3
votes
1
answer
637
views
Does PDO::quote helps me to protect me against sql injection?
I have to process raw sql user input with Laravel. I've backed them up as follows:
...
2
votes
2
answers
87
views
Unnecessary loop in database population
I was looking over some code that I wrote years ago (that is still technically working, albeit on a very quiet production server) and I came across this segment of code.
...
1
vote
2
answers
174
views
Is this code written safe from attacks?
I have small question. I don't know much about JavaScript (jQuery) or AJAX and I don't know whether I'm doing it safe from XSS Attacks, SQL injection and that stuff. I think the PHP with MySQL would ...
2
votes
1
answer
292
views
What is the best way to use serverside validation in PHP PDO?
I have a form on my page. I am using jQuery validation for client-side and PHP for server-side validation. I am using PDO. I don't have any issues with client-side and server-side validation. My form ...
2
votes
1
answer
100
views
Does this PDO process look protected from SQL injection?
Does this process look protected from SQL injection attacks?
Is there something I could possibly change to make it more protected?
...
1
vote
1
answer
81
views
Reduce database touches for one to many data pull
I have the following function which works properly and returns all of the rows from a specific table, then loops through each row to add data related to it as a subarray.
...
5
votes
3
answers
1k
views
Dynamic insert function for PDO (for any case)
I created a dynamic insert function for PDO.
It does work, but I want to be sure that it is secure and well coded.
...
2
votes
1
answer
88
views
Extract users and privileges from MariaDB and MySQL
This was born out of a need to create database users on a new server to allow views to be created correctly when restoring databases. This is designed to be run from a command line NOT via a web ...
3
votes
1
answer
1k
views
Add post to favorite in PDO and mysql
After lot of research and couple of questions in https://stackoverflow.com/ i managed to create Favorite System in PDO mysql as ...
2
votes
0
answers
365
views
PHP Secure Remember Me for Login using PHP Session and Cookies with referer url
I have followed a mysqli tutorial to create a login with cookies and session with remember me authentication in pdo.
in tutorial class had a new db_connection, I ...
4
votes
4
answers
2k
views
Simple login script with sha256 hashing
I have been using this code for a while. I got it from a tutorial 5 years back. Now I'm wondering if it still is secure, or if it's time to find a new one? Maybe it has never been secure enough.
...
3
votes
1
answer
105
views
PHP complete pagination code
I'm working on a site where you can read about different songs, listen to them, rate them etc, same with their singer.
I've been thinking about how I could create a simple, yet perfectly working ...
2
votes
1
answer
246
views
PDO Is this registration secure and well coded?
i finally have been moved to PDO (from MySQLi) and i m now trying to make simple login and registration page (for training purposes).
This code does work! But i want to know if it is secure?
Also ...
1
vote
1
answer
64
views
Categorize & sub categorize from contents of one row and more execute even more queries in results
I have a table called sales and it has below columns:
'id'
'product_type'
'soldDate'
'text'
...
4
votes
2
answers
132
views
Query to plot a histogram of song ratings
I wrote code to plot a rating distribution, which looks like this:
The most important function is the stats function:
...
2
votes
2
answers
70
views
SQL prepared statement to search songs by various text fields
As we know, using PDO and prepared statements, binding a table or column using bindParam is not possible. So for this, I've figured out to use function parameters ...
5
votes
4
answers
147
views
PDO MySQL queries for web application to reserve a vehicle
I normally use MySQLi and this is my first time trying out PDO. I am doing this because this is my first web application that is going to be used by the public, hence I want it to be secure. The code ...
1
vote
1
answer
133
views
Connect to database, handling errors
I try to handle or catch possible errors with PHP/MySQL for security reasons and would like to know if I'm doing it right.
The first case, connection: I use it as a function and call it always when ...
4
votes
3
answers
199
views
User management OOP php class
I found a class that i coded for an old project about a year ago and i haven't really touched php in a while. Now i need to use similar functionality again i thought it would be the perfect time to ...
1
vote
1
answer
109
views
Database connection and DataMapper
Following my previous question Database interface and PDO adapter, I wrote a new simple class to connect to Database and run a query returning a PDO statement.
...
2
votes
1
answer
649
views
Database interface and PDO adapter
I'm writing my own framework in PHP and I want respect the SOLID principles.
I made this interface:
...
3
votes
2
answers
202
views
Elegant and secure way to create a dynamic query
I want to create a dynamic query to display:
all the invoices if the user has moderator rank
only his invoices if the user is a simple member
code
...
1
vote
1
answer
97
views
Displaying a paginated list of forum topics using PHP PDO [closed]
Can someone tell me if this code is safe? Can be sql-injected or something else hacked? Code get some rows from db and show in pages with pagination... if i can improve let me know and show me how, ...
4
votes
1
answer
69
views
Proper use of mysqli->close();
database.config.php
...
2
votes
1
answer
156
views
PDO library to handle MySQL queries
This is my library class. This does not have any issues but I want to know if I have any mistakes, or ways to improve performance:
variable and call (example of ...