pdo

PHP PDO with Special Characters

陌路散爱 提交于 2020-01-01 11:53:32
问题 I am using PDO for MySQL database connection, selecting, updating and deleting. But I have a problem with selecting rows with special characters , for instance, I want to select a page title with 'Judge-Fürstová Mila', Table page , id title content 1 Judge-Fürstová Mila xxx SQL, SELECT * FROM page WHERE title = 'Judge-Fürstová Mila' Returns result if I query via phpmyadmin. But it return 0 with PDO, $sql = ' SELECT * FROM page WHERE title = ?'; $items = $connection->fetch_assoc($sql,'Judge

PHP PDO with Special Characters

♀尐吖头ヾ 提交于 2020-01-01 11:53:27
问题 I am using PDO for MySQL database connection, selecting, updating and deleting. But I have a problem with selecting rows with special characters , for instance, I want to select a page title with 'Judge-Fürstová Mila', Table page , id title content 1 Judge-Fürstová Mila xxx SQL, SELECT * FROM page WHERE title = 'Judge-Fürstová Mila' Returns result if I query via phpmyadmin. But it return 0 with PDO, $sql = ' SELECT * FROM page WHERE title = ?'; $items = $connection->fetch_assoc($sql,'Judge

PDO prepared statement with optional parameters

半城伤御伤魂 提交于 2020-01-01 11:37:08
问题 I'm kind of new with PDO and currently developing the API call that returns search results. How do I set a prepare statement if there are 2 optional parameters for the search query? $app->get('/get/search', function () { $sql = 'SELECT * FROM user WHERE name LIKE :name AND city = :city AND gender = :gender'; try { $stmt = cnn()->prepare($sql); $stmt->bindParam(':name', '%'.$_GET['name'].'%', PDO::PARAM_STR); $stmt->bindParam(':city', '%'.$_GET['city'].'%', PDO::PARAM_STR); $stmt->bindParam('

How to make PDO (pdo_pgsql) to lazily fetch rows

蓝咒 提交于 2020-01-01 10:58:12
问题 With the following code even though I fetch a single row - the whole dataset is downloaded (which takes few seconds): $query = 'SELECT * FROM xxx WHERE id > :position ORDER BY id'; $stmt = $db->prepare($query); $stmt->execute([ ':position' => $position, ]); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { break; } I tried to find an option in PDO that would make it fetch rows on demand (or by reasonable batches), but failed to do so, at least I could not find it in the PDO documentation.

If an PHP PDO transaction fails, must I rollback() explicitely?

非 Y 不嫁゛ 提交于 2020-01-01 10:04:16
问题 I've seen an code example where someone does a $dbh->rollback(); when there occurs an PDOException. I thought the database will rollback automatically in such a case? 回答1: If you don't commit not rollback an opened transaction, and it's not commited anywhere later in your script, it won't be commited (as seen by the database engine) , and will automatically rolled-back at the end of your script. Still, I (well, almost) always commit or rollback explicitly the transactions I open, so : There

Possible PDOException Errors (MySQL 5)?

荒凉一梦 提交于 2020-01-01 08:45:47
问题 So I'm setting up an installer for my web app, and have input fields for database credentials. Part of my validation process includes testing the database connection (using PHP's PDO library). If the connection fails, I want to be able to differentiate between a bad password, bad address, nonexistent database name, etc. so I can reference the proper input field on the form. Can anone point me towards a reference that outlines the possible error codes/messages that are returned with a

Exclude top and bottom n rows in SQL

别说谁变了你拦得住时间么 提交于 2020-01-01 07:19:06
问题 I'm trying to query a database but excluding the first and last rows from the table. Here's a sample table: id | val -------- 1 1 2 9 3 3 4 1 5 2 6 6 7 4 In the above example, I'd first like to order it by val and then exclude the first and last rows for the query. id | val -------- 4 1 5 2 3 3 7 4 6 6 This is the resulting set I would like. Note row 1 and 2 were excluded as they had the lowest and highest val respectively. I've considered LIMIT, TOP, and a couple of other things but can't

php postgresql pdo copy from stdin

不想你离开。 提交于 2020-01-01 05:23:07
问题 COPY table_name ( field1, field2, field3) FROM STDIN CSV; 1,2,"q w" 3,4,"a s" 5,6,d \. How to execute this query by PDO ? Update: Problem is PDO driver executes this query as statement. For example, if you paste it into pgAdmin, it throws an error. I need execute it in psql : C:\Users\User>psql -e -h localhost -U postgres db_name psql (9.1.2) db_name=# COPY table_name ( field1, field2, field3) FROM STDIN CSV; COPY table_name ( field1, field2, field3) FROM STDIN CSV; Enter data to be copied

Is a pdo wrapper really overkill? [closed]

爷,独闯天下 提交于 2020-01-01 04:15:06
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I have done some research about using a databasewrapper for my data. However, I read some posts where people claim you shouldn't use PDO for a databasewrapper because it already is one. That may be so, but I am still convinced that it has a lot of benefits. You handle all

PHP PDO MySQL Transaction code structure

怎甘沉沦 提交于 2019-12-31 09:05:21
问题 I am trying to set up my first transaction in MySQL using PHP/PDO... I just have a quick question, what is the best way to determine if the previous query was successful or not? Here is what I have right now, but I would rather find a way to test the query with an if statement. This is pretty much mock up code to try to get a working model.. I know $results isn't effectively testing if anything was good or bad.. i have it there more as a place holder for the real deal when the time comes.. if