pdo

Problem creating a database with PHP PDO

Hello guys, I'm having a problem with a SQL query in my PHP Application. When the user access it for the first time, the app executes this query to create all the database: CREATE TABLE `databases` ( `id` bigint(20) NOT NULL auto_increment, `driver` varchar(45) NOT NULL, `server` text NOT NULL, `user` text NOT NULL, `password...

PDO using singleton stored as class properity

Hi again. OOP drives me crazy. I can't move PDO to work. Here's my DB class: class DB extends PDO { public function &instance($dsn, $username = null, $password = null, $driver_options = array()) { static $instance = null; if($instance === null) { try { $instance =...

php pdo connection scope

Hey guys I have a connection class I found for pdo. I am calling the connection method on the page that the file is included on. The problem is that within functions the $conn variable is not defined even though I stated the method was public (bare with me I am very new to OOP), and I was wondering if anyone had an elegant solution othe...

problem binding parameter to pdo statement

Having problem with binding parameters to PDO statement. "orderBy" seems not to be passed to query and results are not ordered as suppose to. When I use "price" in query itself all is good but cannot bind paremeter via bindParam. The code is: class Products { const ORDER_BY_NAME="name"; const ORDER_BY_PRICE_PER_UNIT="price_per_unit"; ...

PDO not generating an error

I'm troubleshooting a prepared statement but I'm getting nowhere. I think this is because PDO is not generating an error. I've called: $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); And am trying to get it to insert as follows: $stmt = $db->prepare23423("INSERT INTO ".DB_TABLE_PREFIX."quote (email,reference,started) VA...

PDO Database Connections Problem

Hey Everyone, Over a year ago I created my own database classes which use PDO, and handle all preparing, executing, and closing connections. These classes have been working great up until now. There are two different database severs I am grabbing from, MySQL, and MS SQL Express. I am retrieving an employee id from the MySQL server and...

Can I make PDOStatement->fetchObject not use non-member variables?

Lets say I have a class like this: Class User { var $id var $name; } And I run a query using PDO in php like so: $stm = $db->prepare('select * from users where id = :id'); $r = $stm->execute(array(':id' => $id)); $user = $r->fetchObject('User'); If I vardump my user object it has all kinds of other fields in it that I have not ...

Learning OOP in PHP, trying to refactor my code. Can't connect to database anymore.

Thought I understood how classes work, then I tried this code: class user { var $dbcon; var $dbinfo; var $con; var $error; function dbConnect() { $this->dbinfo['server'] = "localhost"; $this->dbinfo['database'] = "foolish_faith"; $this->dbinfo['user'] = "user"; $this->dbinfo['password'] = "password...

Database Abstraction & Factory Methods

I'm interested in learning more about design practices in PHP for Database Abstraction & Factory methods. For background, my site is a common-interest social networking community currently in beta mode. Currently, I've started moving my old code for object retrieval to factory methods. However, I do feel like I'm limiting myself by ke...

zend_db_select with a hexadecimal query parameter against a binary column

How do you represent this query as a Zend_Db_Select? select * from t where id = x'0cc175b9c0f1b6a831c399e269772661'; The database is MySQL, using either PDO or mysqli adapters. ...

problems, custum wrap (class) around PDO, doesn't work

DB::construct(); $STH = DB::prepare('INSERT INTO users (username, password, email, activationkey) VALUES (?, UNHEX(?), ?, ?)'); var_dump($STH); $result = $STH->execute(array('test', 'nils', '[email protected]', '227a038fe9c81515b514cb152188e95c')); echo "working? <br />"; if($result == false) echo 'noooo...'; It outputs and doesn't put an...

Any suggestions to improve my PDO connection class?

Hey guys I am pretty new to pdo so I basically just put together a simple connection class using information out of the introductory book I was reading but is this connection efficient? If anyone has any informative suggestions, I would really appreciate it. class PDOConnectionFactory{ public $con = null; // swich database? ...

Is PDO for SQL Server support query contain Link Server

Is PDO for SQL Server support query contain Link Server ? I try using mssql_connect but it didn't work. I have try PDO but it alwas return error on query() method. ...

XAMPP, MAMP, MySQL, PDO - A deadly combination?

Hey folks, Previously I've worked on a Symfony project (MySQL PDO based) with XAMPP, with no problems. Since then, I've moved to MAMP - I prefer this - but have hit a snag with my database connection. I've created a test.php like this: <?php try { $dbh = new PDO('mysql:host=localhost;dbname=xxx;port=8889', 'xxx', 'xxx'); fore...

Why is htmlspecialchars adding slashes to my webpage?

I have my input placed into mySQL through a PDO prepared statement, and have it placed in my website with PHP using htmlspecialchars() to protect against XSS. Only problem is now I get slashes, before any quotes, that are visible on the webpage to the user it only happens when I upload it to the server. Never happens on my localhost. Wh...

WHERE clause confusion with PDO

I'm having some trouble understanding how to use prepared statements, when you need to match one value against several columns at once. In other words what instead of doing this: $stmt = $dbh->prepare("SELECT * FROM REGISTRY where name = ?"); $stmt->bindParam(1, $name); I wanted to do this: $stmt = $dbh->prepare("SELECT * FROM REGI...

PHP: How to cast object to inherited class?

I'd like to inherit PDOStatement class and use it in my website scripts. But I am frustrated how to get required object. PDO::query returns only direct PDOStatement object and looks like there are no other method to create PDOStatement object or inherited class. Initially i thought to move PDOStatement object to constructor of inherit ...

Return the exact ID using fetch_assoc

Hi, I have a small problem in my code and I need your help. Well Im using fetch_assoc to get data from database and I need to get the ID number of each of returned values. the issue is that my code only return the ID number of the last data. Here's my code: <form method="post" action="action.php"> <select name="album" style="border:1...

sqlite ERROR no such column

Hi, Does anyone here have some experience with this error? Only If I use the WHERE clause, I get this error. I use php PDO to get the results. And this is my simple table $sql = "CREATE TABLE samenvatting ( stem_id INTEGER PRIMARY KEY AUTOINCREMENT, poll_id TEXT, stem_waarde_id TEXT, totaal INTEGER )"; $crud-...

Accessing DB via function vs object, difference?

Possible Duplicate: PHP PDO vs normal mysql_connect So in my application, I accessed the database via a function named db_connect();. Quite simply, it fed the requisite login information and opened a database connection via mysql_connect and mysql_select_db. Now that I'm working, I have found that the lead programmer uses PDO...