Все вопросы: [pdo]

138 вопросов

похожие теги:
4
голосов
4ответов
8891 просмотров

Is it possible to check if pdostatement::fetch() has results without iterating through a row?

I have a page which needs to check for results, and the way I came up with to do it is successful, but iterates through the first row of results. Is there a way I can check without iterating, or to go back to that first row without executing the query again? I was doing this: $q = pdo::prepare...

1
голосов
2ответов
594 просмотров

What's the most efficient driver to use with ADODB to access a MySQL5 Database?

I've been using ADODB for PHP on several projects for quite some time, and I like it for the ease of use and the efficiency. I've never been too curious about the way that lib accesses data because you know...it just worked :) But today I realized I'm still relying on the legacy MySQL4 ADODB dri...

25
голосов
5ответов
9990 просмотров

Escaping column names in PDO statements

I am currently building a query where both the field/column and value parts possibly consist of user inputted data. The problem is escaping the fieldnames. I'm using prepared statements in order to properly escape and quote the values but when escaping the fieldnames i run into trouble. mysql...

123
голосов
10ответов
102084 просмотров

MySQL check if a table exists without throwing an exception

What is the best way to check if a table exists in MySQL (preferably via PDO in PHP) without throwing an exception. I do not feel like parsing the results of "SHOW TABLES LIKE" et cetera. There must be some sort of boolean query?

10
голосов
1ответов
28677 просмотров

PDO looping throug and printing fetchAll

I'm having trouble getting my data from fetchAll to print selectively. In normal mysql I do it this way: $rs = mysql_query($sql); while ($row = mysql_fetch_array($rs)){ $id = $row['id']; $n = $row['n']; $k = $row['k']; } In PDO, I'm having trouble. I bound the params, then I'm savin...

3
голосов
1ответов
1158 просмотров

Help troubleshooting PDO prepared statement

I've just started learning aboud PDO and prepared statements (which sure seem to beat remembering to use mysql_real_escape_string() every time) but I'm having trouble getting the script to execute properly: <?php error_reporting(E_ALL); echo "start"; try{ $dbh=new PDO('mysql:host=localho...

8
голосов
1ответов
4568 просмотров

PDO - Working with table prefixes

I like to prefix my tables in case I need to install the application to a host with only one database. I was wondering if there is a simple way of working with table prefixes using the PDO class? At the moment, I am having to overwrite each method in my own database wrapped, replace %p with the ...

35
голосов
1ответов
46227 просмотров

PHP PDO prepared statements

I was told today that I should really be using PDO and prepared statements in my application. Whilst I understand the benefits, I am struggling to understand how I implement them into my workflow. Aside from the fact that it makes code much cleaner, should I have a specific database class which h...

3
голосов
3ответов
3060 просмотров

How to get PHP command line to work with PDO?

I want to work with PDO, through PHP command line. It works perfect through the PHP web API, but not through the command line. But when I execute the command: php test.php, it says unknown class PDO. I think it has something to do with the thread-safety difference. Because, when I execute the a...

5
голосов
4ответов
18710 просмотров

Equivalent of mysql_list_tables in PHP PDO?

When using PHP PDO to access the database, is there a way to list all the tables in a database? Something like mysql_list_tables() is whats needed.

0
голосов
1ответов
279 просмотров

Need help with pdo_mysql and data mapper pattern

I'm having issues with php-cgi.exe crashing while using php-pdo-mysql.dll. I'm using the data mapper design pattern show in Padraic Brady's Zend Off The Deep End and everything has been working correctly. I have a table which stores an ip address whitelist, and I'm able to access that properly ...

0
голосов
1ответов
522 просмотров

In PHP does the PDO::PDOStatement->bindParam() work as it is expected?

I am trying out PDO in PHP for the first time. I thought that PDOStatement->bindParam() would be a cool way to set the datatypes of the values that i pass in to the sql query. But somehow it doesnt work for me. For example I set the type of a variable to INT in bindParam call. But it still doe...

2
голосов
6ответов
593 просмотров

PDO acts different on two -very- similar queries

The following block of code works fine (no errors) $query = "select * from users where username = ?"; $statement = $sql->prepare($query); echo gettype($statement); // -- This returns 'object' $statement->bindParam(1, $username); The following gives: Fatal error: Call to a member function...

2
голосов
2ответов
8797 просмотров

In PHP getting "Class 'PDO' not found" error while trying to connect to Oracle DB

I am trying to connect to my oracle database using PDO but I am getting Class PDO not found error. I have checked that PDO is enabled and it appears so. Still I am not able to trace why I am getting this error. Here is my configure command, cscript /nologo configure.js "--enable-snapshot-build" ...

25
голосов
5ответов
81629 просмотров

Error on creating connection to PDO in PHP

Today, I removed and reinstalled the latest version of lampp in order to move to php 5.30, and suddenly a very simple app is failing to connect to the mysql database. I'm using PDO to connect, and receiving the following error: Warning: PDO::__construct() [pdo.--construct]: [2002] Invalid argum...

5
голосов
3ответов
5839 просмотров

Performance in PDO / PHP / MySQL: transaction versus direct execution

I am looping through a number of values (1 to 100 for example) and executing a prepared statement inside the loop. Is there and advantage to using a transaction - committing after the loop ends - compared to a direct execution inside the loop? The values are not dependant on each other so a tra...

0
голосов
1ответов
1206 просмотров

PDO Connection string for SQL Server 2005

What should my PDO constructor/DSN/connection string look like to connect to a SQL Server 2005 database? $dbh = new PDO('??');

3
голосов
2ответов
3447 просмотров

pdo_mysql vs mysqli when using Zend_Db

If I am using Zend_Db classes to abstract my queries from the backend database, does it make a difference which mysql driver I use, pdo_mysql vs. mysqli? My understanding of pdo_mysql is it is also to provide abstraction, so I'm assuming that if I am using Zend_Db, then I would not be taking adva...

3
голосов
1ответов
541 просмотров

PDO do not run same queries twice?

Good day! I'm trying to run the same update statement with the same params twice and it seems that it is not executed in the second case: $update_query = $this->db->connection->prepare('UPDATE `Table SET `field` = :price WHERE (`partnum` = :partnum)'); $update_query->execute(array(...

1
голосов
1ответов
180 просмотров

MySQL query sets field to 0 instead of blank string

This one's puzzling me. I have a MySQL query, being run though PDO: $stmt = $db->prepare( "UPDATE member SET acode='' AND status='active' WHERE username=:u" ); $stmt->bindValue( ':u', $member->username, PDO::PARAM_STR ); $stmt->execute(); The acode field gets set to 0 for some reas...

46
голосов
12ответов
46549 просмотров

PHP PDO vs normal mysql_connect

Should I use php PDO or normal mysql_connect to execute database queries in PHP? Which one is faster? One of the big benefits of PDO is that the interface is consistent across multiple databases. There are some cool functions for prepared statements too, which take some of the hassle out of esc...

0
голосов
2ответов
476 просмотров

php authentication script

I need the following authentication script finished. I am weak at php/pdo so I do not know how to ask for the number of rows equalling one and then setting the session id's from the results of the query. I need to not only set the $_SESSION['userid'] but also the ['company'] and the ['security_id...

10
голосов
1ответов
9579 просмотров

PDO: check for updated or inserted record using mysql INSERT ON DUPLICATE KEY UPDATE

Using PDO / PHP and MySQL, how can I check if a record was inserted or updated when I use an INSERT ON DUPLICATE KEY UPDATE statement? I have seen a solution using mysql_affected_rows() for PHP, but I am looking for a way I can use with PDO.

105
голосов
9ответов
99656 просмотров

How do I insert NULL values using PDO?

I'm using this code and I'm beyond frustration: try { $dbh = new PDO('mysql:dbname=' . DB . ';host=' . HOST, USER, PASS); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); } catch(PDOException $e...

0
голосов
1ответов
213 просмотров

PDO not reading config correctly

I'm not sure what the problem is here, I've inherited some code form Zend Framework and it's using Propel to make DB Queries. I've changed the config file to have the right values in it, username, password, localhost and dbname however, whenever the site has to make a database call it dies with t...

3
голосов
5ответов
9656 просмотров

Insert password hash using PDO Prepared Statements

In a basic mysql insert you are able to set a password variable 'PASSWORD($password)' but this breaks a PDO statement. How do you hash the password while using pdo::prepare and pdo::execute? $sql= "INSERT INTO contractors (userid, password, name) VALUES ('$userid', '$pass1', '$name')"; $resul...

0
голосов
1ответов
93 просмотров

PDO Query question

I need help finishing this statement. It is frustrating that two of the PHP phone books here gloss over PDO's almost all together. All I need to do is check the database for a username that is already taken. Here is the start of the statement. $sql = " SELECT * FROM users WHERE userid = '$u...

2
голосов
3ответов
7632 просмотров

Php pdo result of JOIN query

My problem is I try to do a simple JOIN between two tables, that both have the id field. My result is an stdClass object, as I use PDO. Does anyone know how can I make a difference between the id of the first table and the id of the second table? Code $sql = "SELECT * FROM products AS p ...

3
голосов
3ответов
679 просмотров

when/where we use PDO?

I want to know when and where we use PDO's other than simple mysql_connect methods? Is this PDO is faster ? what are the advantages over other methods?

4
голосов
1ответов
4419 просмотров

How to use MySQL functions when building a query with Zend/PDO

I'm using Zend Framework with the PDO MySQL adapter and I want to use a function in my insert statement. Basically, the SQL I want to generate is this: INSERT INTO `myTable` (`leftId`, `rightId`, `date`) VALUES ($left, $right, NOW()) This is the code in my Model: $data = array( "leftId" =...