PDO is a PHP extension that serves as a data access abstraction layer for accessing databases.

learn more… | top users | synonyms

1
vote
2answers
36 views

Select random row using PDO

What do you think of this way to generate a random number from the total rows in a table? I would like to create a page that random.php precisely generates a random ID and shows it. ...
0
votes
0answers
19 views

simple fetching data and conversion into json using two different pattern

I'm trying to fetching the data and convert into json format. Some days ago I was using the mysqli but someone told me this is susceptible to SQL injections when i asked a question for code review. ...
4
votes
2answers
66 views

Using PHP PDO to Fetch Employee Details

Introduction Hi, I am finally making the move to object oriented PHP. This has been something I have been quite reluctant to do, but I now feel that it could benefit me, and bring me up-to-date with ...
1
vote
0answers
39 views

Efficient MySQL PDO Class

I tried to create a secure and efficient PDO class.I would really appreciate your feedback to make it more production ready.Github Link ...
1
vote
0answers
21 views

Bulk customer creation

Here is my script which takes 50k records from a CSV and does CRUD operation with them. Unfortunately there are a lot of issues with the performance. CSV fields are: msisdn, resellerid, product ...
2
votes
2answers
73 views
0
votes
1answer
48 views

Inserting a role using PDO

My question has to do with : (a) Can this be made more secure? (b) Are there best practices in relation to setting timezone? (c) What best approach should be taken defining use of utf8? ...
1
vote
1answer
81 views

PHP Login script getting bypassed allowing access to my admin pages

I have a site where a friendly hacker says they have accessed my admin area. I am not able to see how this is possible so any help would be greatly appreciated. I am using PDO prepared statements to ...
1
vote
1answer
81 views

Global site settings middleware for Slim Framework 3

I have created this middleware code for slim. I just want to know that is this right way to store site settings globally. so, I can use where ever I want. What do you think about my class structure ...
1
vote
2answers
64 views

Details of a user

Would you please recommend how I could improve this code? My PHP editor only gave a warning about the variable $id. ...
1
vote
1answer
41 views

Database query inside a method of a class and return data [closed]

I'm trying to find out what is the right approach to return DB values from a class. This is what I came up with: ...
0
votes
1answer
65 views

Proper class user.php

I'm learning to program with PHP, so I ask your help to check if my class user.php is ok. ...
2
votes
1answer
55 views

PHP page to edit a user account information and avatar

I wanted to ask your opinion about my code created for acccount.php page for editing the data of each logged-in user. I wanted to have more of an opinion on your right syntax, though maybe it could ...
4
votes
1answer
41 views

PDO connector class

I have created a DB connector class with PDO. Do I need to add, delete or edit anything in this code? ...
2
votes
2answers
41 views

PHP Dynamic QueryBuilder function - Security

This function is a working function, which builds a number of queries depending on the values of $_POST. ...
3
votes
1answer
56 views

Possibility of SQL Injection

I am requesting a review of a portion of a 600 lines of code. This portion of the code process a filter that is farther down the page. It takes in the parameters and formats them into a query. Now I ...
2
votes
1answer
61 views

Writing PHP PDO bindParameters

Is there a better way to write this? ...
3
votes
1answer
47 views

Extended PDO class for MySQL

I recently started with object oriented programming in PHP and I am wondering if my database class is on the right track. Am I doing something wrong? If so, how can I improve it? Here is the class: ...
5
votes
1answer
70 views

Tools for transferring data from an API to a database

I explain everything on my current code but this question is more general "HOW TO" work correctly with this in this case but even next time. I have 4 methods in my class, each does something but in ...
4
votes
1answer
59 views

Database Session Class

I have made the decision to move the storing of session data from the filesystem to the database. Our application is growing at pace and we are having issues with the load balancer breaking the ...
2
votes
2answers
53 views

Returning the number of records per day

I'm writing a query to get the number of sessions created each day for the past 90 days. I'm currently using a prepared statement to do this - looks something like this: ...
6
votes
2answers
91 views

A class to add and select players within a database

I have a question and want to know if my class is considered object oriented. ...
3
votes
2answers
69 views

Classes, one responsibility principle and magic methods

I am currently building a small application that allows users to create a slideshow, each slideshow consisting of slides that are either videos or images. Although this will be relatively small at ...
3
votes
3answers
226 views

Web page to add a notice, with some validation

I'm displaying multiple queries and if statements. In the if statement, it increments ...
1
vote
1answer
133 views

PDO - configuration, database connection & and using

I'm currently reading a book and watching some tutorials about PHP with MySQL (PDO), but it is not clear where to put certain things - where to put some code, should I put the connection to the ...
0
votes
1answer
38 views

Bind variables in PHP-MySQL

I am using the below code to execute a MySQL query in PHP. ...
0
votes
1answer
132 views

PDO lastInsertId

In my shop system I'm using the PDO lastInsertId to assign the order_id to the products that belongs to it like this: ...
5
votes
1answer
273 views

PDO Insert function using PHP

This code inserts data into the database successfully. I was concerned about whether it is a considered good practise to go about inserting data into the database in this way. Is there something I am ...
3
votes
1answer
202 views

Custom error/fatal error and exception handler in PHP

Introduction I wrote three functions that aims to log errors and exceptions as well as show a user a generic error page. Would appreciate some feedback on it with regards to the PSR standards and if ...
1
vote
1answer
196 views

PHP script to connect to MySQL database using PDO

Introduction I am preparing to use a basic script to cover how you can connect to a MySQL database using PDO. This script is meant for educational purposes (introductory class on PHP/MySQL) and does ...
0
votes
2answers
609 views

MySQL JOIN to JSON array

I'm building a HTTP API and this part should return a JSON list of posts and their attached photos, like this: ...
3
votes
1answer
429 views

PHP class architecture and dependency injection

Let me start off by saying I am not new to PHP or PDO, but very new to OO PHP, and have been struggling to get a firm idea of best practices in my head regarding dependency injection and structuring ...
2
votes
2answers
153 views

PDO Database Auto Table Creator

How can I do the following with less nested loops. How can I output the Table names above their corresponding tables without having to loop. Functions for returning the DB Info: ...
2
votes
1answer
90 views

Fetch entire table from database after validating the table name

I'm creating a database class. It's part academic and part something I may show in an interview. The purpose of this method is to accept a table name as a parameter, check if the PDO Object has been ...
2
votes
1answer
77 views

Retrieving result sets from a MySQL table

This retrieves result sets from a MySQL table. The objective of this function is to correctly retrieve any number of rows (with $sql) from a MySQL table, binding ...
60
votes
3answers
3k views

Shielding your CodeReview on GitHub

In response to a feature-request on meta, I spent a few hours today creating the feature in php. This application adds a review shield to your GitHub repository (or wherever else you want it). It ...
2
votes
1answer
75 views

Function to streamline PDO statements

This function arguably has little use as it's so simple, but I'm writing a web application with a lot of SQL statements littered all over the place and I thought this function might reduce code ...
5
votes
2answers
2k views

Slim API with 3 layer architecture

I'm new to Slim and the three layered approach I'm using below. So far I have the API, a Presentation layer (leaving out for now), a Business Logic Layer, and a Data Access Layer. The code's working, ...
4
votes
0answers
157 views

Write a HTML table from MySQL tables

I have a piece of code that generates some tables: bp_rows: where I take a snapshot of some "headers" for each row of the table. ...
2
votes
2answers
174 views

PDO wrapper with validation

After moving from mysql_ to PDO I created a PDO handling function. Basically this function takes parameters, checks them and returns end result. The thing is that I created this ~1 year ago and ...
2
votes
2answers
69 views

Storing customers' orders

I'm developing a shop system and using this method to store the customers with their respective orders: ...
4
votes
1answer
130 views

Selecting and inserting MySQL records using PDO

This PHP class connects to and queries the database MuSKL. I am a novice, and I ask you to comment on the approach and style of code. ...
4
votes
3answers
69 views

Database select script

Is there any way I could improve this script, such as by writing it in fewer lines (more efficient)? I'm very interested in keeping my code dry and fast! Also, if there is a way to make it more ...
3
votes
1answer
89 views

Handling DB transaction in closure

I think DB transaction should be as small as possible, and close it soon. So I wrote a helper function like 'using' statement in C#. ...
2
votes
1answer
52 views

Placing navigation items into an array

I am looking for better ways to write this code. At the moment it grabs a list of all navigation items and places them into an array (using PDO). However, as you can see, it is using two ...
3
votes
1answer
383 views

Authentication using PDO

I'm new to PDO, so I was wondering if you guys could check over my PDO code for efficiency (and if the PHP can be improved) ...
2
votes
1answer
230 views

Secure login system

The assignment is to create a login system secured for SQL injections and XSS. It's in PHP and I'm using PDO with prepared statements obviously. Which from my point of view should protect against the ...
0
votes
1answer
75 views

Syntax form PDO

I was able to run the form to update the data of the user profile, for the moment is in a rough version, but I know that can be improved. I post what I did, I hope you could help me to improve the ...
2
votes
1answer
368 views

PHP login system security using a database, cookies and sessions

I created a simple login system using just sessions but having to login every time gets annoying. That is why I'm no trying to save the sessions to my database linked to the user's account. I will ...
1
vote
2answers
222 views

PHP PDO Helper Functions

Just recently I've wanted to update the PHP scripts I use to fetch information from a database for an iOS application. I've got around to it today, and I had a few questions that'd I like a second ...