PDO is a PHP extension that serves as a data access abstraction layer for accessing databases.
0
votes
2answers
27 views
How do I put $db in a central location, but maintain variable scope
I have that $db, that I will use again and again to connect to the database. How do I put this in a central location so if I change my db I will not have to rewrite a bunch of lines of code? ...
1
vote
0answers
31 views
Pages system PHP/SQL
I'm working on a CMS, currently on being able to create static pages, manage menus etc.
so.. I have This function that reads from the DB and finds all the static pages, and their position in the menu.
...
1
vote
1answer
39 views
Creating a PDO abstract parent class
I think many people for some reason use a singleton class to handle the PDO connection (?) but I was thinking it would be nice to have a parent abstract class initializing the connection and the child ...
0
votes
3answers
103 views
Can this code be simplified even further?
Can I make any further improvements to simplify / speed up this code? My reason for creating new arrays for the variables $name, $business, $email, $orderstatus is because when displaying results ...
0
votes
1answer
50 views
Can this code be improved upon?
My code already works 100%, just trying to figure out if there is an easier, better or speedier way to do this. Outputs to an HTML table to display results.
Something that took me a while to figure ...
1
vote
1answer
56 views
MySQL vs PDO execution time
I'm having some issues understanding why PDO is 6X slower executing a query than the depreciated MySQL query function. Here's my code:
$conn = new PDO('mysql:host=localhost;dbname=work', 'root', ...
3
votes
1answer
57 views
Performance on PHP sql queries
I'm barely learning PHP and MYSQL so I don't know much about performance, I've wrote this script to fetch and format content from my DB, it also counts how many result are and separate them in to ...
3
votes
1answer
50 views
How do I refactor this basic form handler
I've dabbled with PHP for a couple of years, I can generally get what I need done and I've been teaching myself PDO. The problem is I want to set it up with classes but i'm not really sure how to.
...
0
votes
1answer
55 views
Something wrong with this code? [closed]
Hey been at this for a day can't fix the problem.
This function updates user info in the db [MySQL]
it keeps throwing the exception Couldn't update user
<?php
function update_user($user_id, ...
1
vote
2answers
67 views
PHP PDO mysql multiple queries mak
I ran into a problem, I'm using MyIsam tables in mysql database, using PDO to connect.
In all my tests (calling for 1 user everything works fine), now having around 300 users connected at the same ...
4
votes
1answer
68 views
Code Reiview for an PHP PDO Queries? is there a better way to do it?
so this is my code for a equipping an item in my game dev't:
try {
$db = getConnection();
$db->beginTransaction();
$sql_chara_gold = $db->query("SELECT chara_gold ...
1
vote
2answers
100 views
Assist cleaning up messy HTML/PHP code
I really hate messy code, but I seem to be rolling in it. I just want to see if anyone has some helpful advice on how to tidy this up.
<table>
<tbody>
<tr>
<th>Zona</th>
...
4
votes
1answer
91 views
Create a table from MySQL using PHP PDO
I am trying to simply present a table in HTML that is stored in a MySQL database. I would like to use Object Oriented PHP to access and fetch the data for the table. I have spent some time learning ...
3
votes
2answers
152 views
Is this code safe from SQL injection?
I believe with everyone's help on StackOverflow I got my code safe guarded from SQL injection, trying to confirm that is correct, just in case I misinterpreted the help and advice I received.
...
2
votes
2answers
86 views
PDO database class review
I've taken this class and made it my own but I'm curious to know what other think of it? Are there things I'm missing? Anything you can recommend?
class Database {
private $host = '';
private ...
3
votes
2answers
280 views
Review my PHP login and register script, and profile page, and how to improve them
There are some things that I know that need to be fixed, such as mysql_* needing to be converted to PDO, and using a better hash. I am working on building a social networking site, and I've been ...
4
votes
1answer
53 views
Thoughts on organizing code for multiple mysql queries in php scripts
I have a web application where I connect with a MySQL database using PDO and in some scripts there are a lot of queries one after the other which don't necessarily concern the same tables. i.e I will ...
3
votes
1answer
78 views
Converting from MySQLi to PDO account activation
I had been working on a project for some time, and then it went on the way back burner after my daughter was born. I'm back to it, and now I discover that I'm best off using PDO over MySQLi. So, I'm ...
4
votes
1answer
294 views
PHP Extending PDO Class
I am trying to convert myself from using mysql extension to using PDO, with that being said I was curious if I am going about this the right way.
I have a custom logging system that I built I am ...
0
votes
2answers
92 views
PHP PDO Custom class ple
i created a database class from a good tutorial and wanted to put it up here so it would get in some search results. it took me about 2 days to find it. also i added a few custom functions to it.. ...
3
votes
2answers
206 views
PHP PDO Factory Classes
So, my question is more of a 'best practices' question rather than a question with a particular aim. This is my current understanding of PHP factories and how to incorporate them into a project using ...
3
votes
1answer
108 views
Breakable MVC framework written in PHP
I've written a framework in MVC, I call it Midget MVC, as it's so darn small. The reason I wrote it is because I wanted a lightweight and extendible framework to use in projects. It eventually got ...
2
votes
1answer
91 views
How secure is this PDO Portfolio Script?
I was wondering if someone could take some time to look over my portfolio script and see let me know if it's secure enough to be uploaded live and connected to my database. My previous mySQL script ...
1
vote
1answer
505 views
Is this PHP class good enough for CRUD
I wrote this class to make it reusable in any project.
It uses PDO as the MySQL connection.
Beside not using Setters and Getters, is this code secure and good practice for CRUD ?
Thanks for further ...
-1
votes
1answer
164 views
JSON array data posts but table does not update - PHP - Mysql - PDO - AJAX [closed]
I have a php script that encodes my db table into an array. I echo the json_encode and it echos just fine. script :
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
...
1
vote
0answers
87 views
Is there a more efficient way to do this
I am curious if there is a faster better more efficient way to accomplish what I have in the code below:
<?php
session_start();
//require 'functions.php';
//require 'DB.php';
$employeeID = ...
0
votes
1answer
548 views
How to properly use OOP in PHP with forms
I am trying to wrap my head around how to properly use OOP in PHP when dealing with form submissions.
The example below is a form for editing course information. I have a class called Course which ...
1
vote
0answers
56 views
More than 4000 chars gives string literal too long error on oracle [closed]
I am currently using oci8 driver on Codeigniter.
While updating a field that will have more than 4000 chars, I was given a error :
ORA-01704: string literal too long
So, going through few blogs, I ...
0
votes
0answers
119 views
Translation class with database back-end
From reading the faq, basically I would like if everyone could give me advice on all of the things enunciated there about my code (mainly design pattern usage and security):
Best practices and ...
3
votes
1answer
569 views
PHP: PDO (mysql) basic usage, query variable naming conventions (etc)
After mseancole's answer
I just realized that I was using json_id for 3 of the 4 queries after reading mseancole's hint about putting them into an array. Neat!
Are there more improvements I could ...
5
votes
1answer
140 views
Is there any problem in checking PHP PDO connection this manner?
Is there any problem in checking PHP PDO connection this manner?
Is this way reliable?
function pdo_mysql()
{
$mysql_string = "xxxxxxxxxxx";
$mysql_user = "xxxxxxxxxxx";
$mysql_pass = ...
5
votes
1answer
404 views
PHP Login Authentication with BCrypt
So I have a php authentication script and everything works fine. But I'm very unsure about the way I programmed it (i hardcoded some stuff) and I was hoping stack could look through this and point out ...
4
votes
1answer
184 views
Please review my PDO Database wrapper
The subject is this small project - PHP/MySQL Database wrapper
The three main goals of this projects are:
Easy way to map database columns to object properties
Simple solution to insert or update ...
3
votes
1answer
590 views
How to improve Try…Catch Block for PDO?
I have written a PDO wrapper and a class file like a model. So far, it's looking so good! I am just confuse where I should put Try...Catch block - Would it be better to place in PDO wrapper ...
4
votes
2answers
234 views
moving from->to: mysql->pdo, md5->pbkdf2, procedural->oop
I'm upgrading/rewriting our online client portal and wondering if my log in page code looks okay so far. during this rewriting/learning process I am upgrading a number of things: PHP 5.2 to 5.3.5, ...
2
votes
2answers
61 views
Is this function properly structured, leading to a secure row insertion?
I have the following function to insert a new row into a table:
/**
* Insert row into the designated table
*
* Function to add a new row into the designated table
*
* @param str $table ...
6
votes
2answers
388 views
Is this PDO wrapper structure dynamic? and can using self:: rather than $this cause problems?
<?php
class Database
extends PDO
{
/*@var mixed $stmt Used as a temporary variable to hold queries*/
private $stmt = Null;
/*@var $scopeSelectVar Used as a temporary variable to hold ...
1
vote
1answer
1k views
PHP PDO wrapper class
I'm one of those coder/designers that has been at it since day one, but is still getting the hang of several important coding nuances (e.g. OOP for PHP, and concepts such as this).
In this case, I'm ...
2
votes
3answers
2k views
PHP login system (PDO, sanitizing, hash)
I have made custom login form for my site, with help of PDO (until now i used simple mysql connectinon and sanitising), and it looks like this:
session_name('NEWCOOKIE');
session_start();
...
0
votes
2answers
197 views
PDO class design
I have the following class design for my PDO database access class. Please can someone confirm that this is good practice, or suggest improvements if necessary.
Thanks.
Database.php
class db {
...
1
vote
2answers
270 views
Basic user registration code in PHP: Part 2
Edit1: Edited in response to Corbin's feedback
This is an update of my user registration code. This is continuation and implementation of feedback found in this thread: Previous codereview post.
I ...
1
vote
1answer
548 views
PDO MySQL class
I'm new to using PDO and am trying to create a secure class to handle MySQL statements. Here is what I have so far:
class SQL {
private static $dbh = null;
private function __construct($host, $user, ...
0
votes
2answers
103 views
User lib php v2
I've been working some forth looking on design patterns, and I would like some help to improve the code (fixes, tips, just generally improvements, or things you consider bad practise, etcetera in my ...
3
votes
1answer
359 views
Using PHP's __call() to emulate a Class instead of Extending
I recently started working on a project that had been dropped by the previous dev. When looking through the existing code, I came across this singleton Database Class.
class Database{
private static ...
2
votes
1answer
123 views
Right way to update only certain field on a database row
I have data that I want to insert on a database.
Sometime a piece of data is already in the database, so I just want to update the fields that changed.
For example if I insert these rows one after ...
2
votes
1answer
1k views
PHP DAO classes inherit from a generic DAO classes and only change the table name
I am building a web app that needs to access various tables in a given MySQL db. To do that, I have created a generic class, see DAO_DBRecord.php below, and I create children classes for each table I ...
2
votes
2answers
1k views
PHP: PDO (mysql) connection and query class, safety and logic
For the last few day I tried to figure out how to work with mysql and PDO.
All tough I've tried to read a lot about the subject, still there are a lot of things I don't understand.
Because of this ...
3
votes
1answer
904 views
PDO wrapper class
Connection stored in the xml config file.
<?xml version='1.0' ?>
<database>
<connection>
<dbtype>mysql</dbtype>
<dbname>shoutbox</dbname>
...
1
vote
1answer
311 views
MySQL PDO class
Please give me any comment about these codes. Does it enough to prevent SQL injection? What I have to do to make the code better?
<?php
/**
* Description of MySql
* @name MySQL PDO
...
11
votes
3answers
2k views
PHP PDO Database Abstraction Layer
I'd like to get some feedback on a PHP Database Abstraction Layer I've created. It's a little long, but there really wasn't a way to just post part of it. Here is the base DBObject class for MySQL:
...



