Questions tagged [pdo]
PDO is a PHP extension that serves as a data access abstraction layer for accessing databases.
333
questions
2
votes
1
answer
69
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
62
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
31
views
7
votes
2
answers
122
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 ...
2
votes
1
answer
56
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
171
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
117
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
84
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
132
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
368
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
189
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
104
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
48
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
429
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
304
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
148
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
394
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
82
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
166
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
233
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
97
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
73
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
677
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
63
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
931
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
252
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
1k
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
96
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
198
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
62
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
114
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
68
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
116
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
93
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
130
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
85
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
360
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
107
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
78
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
57
views
Proper use of mysqli->close();
database.config.php
...
2
votes
1
answer
148
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 ...
2
votes
1
answer
307
views
Passing data to HTML template
How can I pass data from database to my HTML template without putting PHP code in my HTML file.
Thanks.
This is my controller
...
4
votes
2
answers
158
views
Rudimentary registration and login system
I'd love for someone to review my code. It works fairly well, but I'm still getting the hang of PHP and want to make sure I've got an iron-clad system that isn't hilariously vulnerable. I'm also open ...
2
votes
1
answer
88
views
PDO / HASH Registration form
I just made my first registration form with password confirmation, hashing with BCRYPT and PDO. As a beginner, looking around on StackExchange, I seem to miss a lot.
To keep it simple for myself, I ...
2
votes
1
answer
353
views
PDO login script
Just started using PDO for my newest project. I'd like to get input on how this login script looks and if I should alter it in any way.
When the user clicks the link to the index.php page, a script ...
3
votes
1
answer
1k
views
PHP PDO search & pagination
I know that OOP is ubiquitous nowadays. Nonetheless I still write procedural PHP. It now seems to me that I had fallen into a spaghetti code trap, because my code starts to seem meaningless even to me ...
2
votes
2
answers
76
views
ORM class for Posts
I'm new to PHP OOP and I'm making some tests. I have 2 classes: database and posts and the two interact with each other.
Class Database:
...
0
votes
1
answer
1k
views
PDO multiple queries with 2 different tables
I joined this 2 tables and dropped the user_id afterwards. I am defining the user_id elsewhere in my code based on my session/cookies and I do not want to return this value as a global. Is there a ...
3
votes
3
answers
2k
views
Dynamic PHP PDO insert method
This is my attempt at making a class for dynamic PDO queries in PHP.
The code works, but I would like the hear what I can improve to make it more secure and readable.
...