All Questions
90
questions
4
votes
2
answers
234
views
A PHP class for the common database operations?
I'm a CS undergrad, so I don't have much experience. But while coding vanilla PHP projects, I found that I was repeating myself a lot with the CRUD operations. So overtime, I developed a single file ...
0
votes
1
answer
74
views
PHP login codes suggestions
Now i have a fully functional PHP codes for login and registeration i was wondering if anyone could offer improvements to the code
The code:
Config.php:
...
1
vote
1
answer
139
views
Follow up to Validation Script in PHP
So I've implemented the suggestions in Original question
And now my code looks like this:
...
1
vote
1
answer
113
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
212
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 ...
1
vote
1
answer
94
views
Is there any sugestions how to make this script faster if its possible?
I wrote a script that uses an uploaded excel file to import data to the database. It checks for the image first if it can be downloaded without any error then insert the rest of the data. With ten or ...
1
vote
1
answer
108
views
Laravel Eager Loading tickets from DB
So I have the following relationship in my Model:
Events Model:
...
2
votes
1
answer
119
views
function to group data by parent branches
I wrote this function to take database output like from PDO's fetchAll(PDO::FETCH_ASSOC) and turn it into a tree. For small datasets it works well. However, when ...
5
votes
3
answers
219
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 ...
-2
votes
1
answer
189
views
Insert row into database using static or non-static method [closed]
I would like to know if there are any benefits of one of the following 2 methods which insert an object into a database
The first function calls the Model method statically, creating a new instance of ...
0
votes
2
answers
184
views
Version 2: Display visitor's number on your web page (changed code after getting answer for first version)
Version 2: Display visitor's number on your web page (changed code after getting answer for first version).
The first version is here: Display visitor's number on your web page
The "visitors&...
0
votes
1
answer
261
views
Display visitor's number on your web page
Display visitor's number on your web page.
The "visitors" table has only one column (visitor_count) and only one row. The column's initial value is 0.
I know goto should not be used but then ...
2
votes
1
answer
232
views
Optimization of laravel pivot table relationship
I have a pivot table called invite_riskarea which is designed as follows:
This table stores the permissions that have a specific user (through an invite id) to ...
1
vote
1
answer
73
views
Search controller logic to search through models and manufacturers
I have the following Laravel controller that searches through two models - Manufacturer and SearchTerm (which contains models of manufacturers, synonyms of models as well as common misspellings) using ...
7
votes
2
answers
204
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
82
views
Object relational mapper - optimize in memory data representation and code improvements
An Object-relational mapper built using php.
This was done for educational purposes, and curious to know what kind of improvement has to be done to use in production.
Please refer to the complete ...
2
votes
1
answer
858
views
MySQL database custom session handler using PHP with MySQLi extension
I have made the decision to move the storing of session data to the database.
Any new ideas, suggestions are welcome.
Please also give security suggestions.
Like SQL injection is possible here, etc...
...
5
votes
1
answer
449
views
A lightweight CRUD, based on the Table Data Gateway pattern
In order to reduce the boilerplate code, I decided to write a lightweight database helper, based on the Table Data Gateway pattern (or at least the way I understand it) with the aim of using it for a ...
1
vote
2
answers
125
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 ...
3
votes
2
answers
562
views
Getting data from database through Ajax post request
Is the method used below to get data from a database efficient and optimal? The data is in a MySQL database, and in my server I have a PHP file with the following code to return some information:
<...
1
vote
0
answers
338
views
Checking if a user exists on the database and return user in JSON format
below code takes data (email,password,user type) from $_POST[] and use them to search whether a user exists on the database. If yes sends a JSON object to the ...
0
votes
2
answers
102
views
Check if ID exist or not
Here I have a class where I'm checking if model_id exists in the table models_web_tbl.
Everything works like a charm but I just ...
0
votes
1
answer
71
views
Login to a school system and get account type
I'm new to MySQL database design.
My question is this database is correctly built or not.
We used the users table to login and get account type
and here the code to login
...
1
vote
1
answer
113
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
719
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
1
answer
39
views
List products based on slug and sidebar filters
This method shows the list of manufacturers' offered products based on the slug and sidebar filters.
Most of the time I have to write the same query with only some changes: you can say I am repeating ...
2
votes
2
answers
102
views
PHP Filesystem JSON Files DB
Regarding the use of the file system as a database to simply hold JSON files.
Any input on this matter from people who know will be appreciated...
...
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.
...
1
vote
1
answer
103
views
PHP flatfile storage
So, I made a tiny (~2 KB, <100 lines) library for simple flat-file data storage.
How it works is, you define a file to be used, and then you can add/read/modify/delete objects as "keys" to/from ...
3
votes
1
answer
68
views
Queries to print out on the screen a list of menus
For common users I have 10 queries and for registered users I have 30 queries like this one below, only to print out on the screen the link for the querystrings, a guy said to me that I should escape ...
-1
votes
1
answer
84
views
Getting data from REST API (JSON), extract variables and upload those to database using MySQL [closed]
I'm working with a REST API, first time doing this and I have a working code but it's long and just looks messy to me. I just know there's a better and faster way to do it.
...
1
vote
1
answer
100
views
Auto generate database table
I have written my own little auto-generated table class, and I was wondering if you guys can give me some tips on how to make this code more elegant and secure and maybe compact it so I use only one ...
2
votes
1
answer
87
views
2
votes
1
answer
313
views
Connecting 2 databases: one for admins and one for customers
I am working with 2 databases.
One for admins ('backoffice') and one for users.
Account managers: Use the 'backoffice' database to manage customer accounts.
Customers: Whenever a users connects ...
2
votes
0
answers
39
views
Many to many (n to m) relationship without insert duplication php
I managed to make a many to many relationship work correctly using mysql, doctrine 2 and symfony 3.4.
When a new element A that contains 0 to m element Bs is inserted, the B elements that already ...
-1
votes
2
answers
123
views
MySQL select between MAX-n1 AND MAX-n2
I just made this link please check this out Online Results
I need to select data between 2 values from a table by using MAX because each SID has different VID.
My code:
...
0
votes
1
answer
54
views
Is using beforeFind() event in background to dynamic update SQL queries a good practice? [closed]
I have a Projects table, which I need to ORDER BY code column. But problem is ...
1
vote
1
answer
86
views
Decrease execution time in updating rows in PHP
Any tips on how the below code can be optimised for faster execution?
I have a table in postgres called staging with the below columns;
...
1
vote
2
answers
521
views
PHP PDO statements
I wrote a piece of code. and to be honest it seems a bit messy so I would like some opinions on it, and if I can make it cleaner. Or if there are better ways to do it:
...
1
vote
1
answer
63
views
Adding words to the database
I created a dictionary web app for my language in PHP. At the beginning of the project I wanted to create not a dictionary but a simple web application that would correct the words that were entered ...
1
vote
3
answers
3k
views
Instantiating a Database connection class in PHP
I am building my own MVC and I have a couple questions about making a database connection and what is the best practice. I have a model User which interacts with ...
3
votes
2
answers
1k
views
User class, taking on login and registration capabilities
Based on the Single Responsibility Principle, I have been looking at my User class, trying to figure out how I can break out more functionality into separate classes.
But it seems like all the ...
1
vote
3
answers
146
views
PHP database calls
I need help to speed up this code. It works, but is really slow (updates 2 items/second). Any tips on how to speed it up?
The script functions like this:
Break up an email to username and domain
If ...
3
votes
2
answers
1k
views
PDO Insert Method
I'm currently creating a class that will have a bunch of my most common database functions. This is the first method I've made, I would appreciate any feedback, thanks!
...
-1
votes
2
answers
232
views
Wrapper Connection PDO PHP [closed]
This is my wrapper, how can i improve this? (With a Singleton too)
...
4
votes
2
answers
23k
views
Simple PDO database class in PHP
I'm writing a simple database class so I could use it in my future projects. It is based on some Codeigniter database methods, but my implementation, so if you could review this, that would be cool. ...
0
votes
2
answers
87
views
Database in Class for Reusability
Does this code fine for database reusability?
...
1
vote
3
answers
123
views
Three PHP database queries to manage accounts
I have a database connection PHP file which has a lot of queries to the database. Here are 3 of the functions that I am using:
...
2
votes
0
answers
90
views
Query for searching for the best transportation
I made a website where is possible to search for the best transportation from a place to another. For instance, if I need to go from Berlin to Bremen, the website will search in its internal database ...
2
votes
2
answers
513
views
Setting up a database class
I am wondering the best way to setup a database class, to remove repeat code by using OOP. This way if I changed how I connect to the database (switch from PDO to sqlsrv driver) I can just change it ...