pdo

Array in the parameter when creating PDO query

泄露秘密 提交于 2021-02-09 20:31:51
问题 Can I use a few lines in the parameter Example SELECT id, city_id FROM an_objects WHERE city_id IN (:arrCity) (:arrCity) (1,2,3,4,5,6) But now I have done like this SELECT id, city_id FROM an_objects WHERE city_id IN (:1p, :2p, :3p, ...... :100p) And it's very bad 回答1: <?php private function PDOBindArray(&$poStatement, &$paArray){ foreach ($paArray as $k=>$v) { @$poStatement->bindValue($k, $v[0], $v[1]); } } // the array structure should now look something like this $inputArray = array( '

Array in the parameter when creating PDO query

与世无争的帅哥 提交于 2021-02-09 20:30:57
问题 Can I use a few lines in the parameter Example SELECT id, city_id FROM an_objects WHERE city_id IN (:arrCity) (:arrCity) (1,2,3,4,5,6) But now I have done like this SELECT id, city_id FROM an_objects WHERE city_id IN (:1p, :2p, :3p, ...... :100p) And it's very bad 回答1: <?php private function PDOBindArray(&$poStatement, &$paArray){ foreach ($paArray as $k=>$v) { @$poStatement->bindValue($k, $v[0], $v[1]); } } // the array structure should now look something like this $inputArray = array( '

PDOStatement::fetch() and duplicate field names

对着背影说爱祢 提交于 2021-02-07 20:49:10
问题 I'm working on a web application using MySQL and PHP 5.3.8. We have a mechanism to translate a simplified query instruction into a complete query string, including joins. Since I cannot know what (normalized) tables there will be joined and what their fields are called, there may be duplicate field names. When executing PDOStatement::fetch(PDO::FETCH_ASSOC) , I get an associated array of field names: $test = $this->DBConnection->prepare("SELECT `events`.`Title`, `persons`.`Title` FROM `events

shorthand PDO query

旧巷老猫 提交于 2021-02-07 20:02:09
问题 Currently to perform a query with PDO, I use the following lines of code: $sql = "SELECT * FROM myTable WHERE id = :id"; $stmt = $conn->prepare($sql); $stmt->bindParam(':id', $id); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); And after some research, I found a shorter way of executing the same command: $stmt_test = $conn->prepare("SELECT * FROM status WHERE status_id = ?"); $stmt_test->execute([$id])->fetchAll(PDO::FETCH_ASSOC); $result = $stmt_test->fetchAll(PDO::FETCH

shorthand PDO query

梦想的初衷 提交于 2021-02-07 20:01:30
问题 Currently to perform a query with PDO, I use the following lines of code: $sql = "SELECT * FROM myTable WHERE id = :id"; $stmt = $conn->prepare($sql); $stmt->bindParam(':id', $id); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); And after some research, I found a shorter way of executing the same command: $stmt_test = $conn->prepare("SELECT * FROM status WHERE status_id = ?"); $stmt_test->execute([$id])->fetchAll(PDO::FETCH_ASSOC); $result = $stmt_test->fetchAll(PDO::FETCH

PDO bindValue with \PDO::PARAM_BOOL causes statement execute to fail silently

痴心易碎 提交于 2021-02-07 12:11:38
问题 In one server setup I experience very strange error. There's PHP 5.3.6 with PDO Driver for MySQL, client library version 5.1.61. Everything is compiled by hand. When I bind params with bindValue and set third parameter as \PDO::PARAM_BOOL then statement execute return false and nothing happens (no data inserted to MySQL, even no exception at all). When I don't use third parameter it goes well. In fact I can't ommit third parameter, bacues Doctrine2 DBAL sets it while converting parameters...

PDO::PARAM_INT behaviour in PHP 7.1 & PHP 7.2

穿精又带淫゛_ 提交于 2021-02-07 08:22:32
问题 When passing a string with PDO::PARAM_INT there seems to be a change of behaviour in PHP 7.2. In Version 7.1 the updated value and the passed string were identical, in PHP 7.2 the updated value is "3" (see example below). Of course I'm aware that passing a string using PDO::PARAM_INT is wrong, but I'm wondering why there is nothing to be found in the PHP changelog and why there is no exception or warning thrown. Does anyone know if this is a desired behaviour? $sql = "UPDATE test SET name =

PDO::PARAM_INT behaviour in PHP 7.1 & PHP 7.2

余生颓废 提交于 2021-02-07 08:20:39
问题 When passing a string with PDO::PARAM_INT there seems to be a change of behaviour in PHP 7.2. In Version 7.1 the updated value and the passed string were identical, in PHP 7.2 the updated value is "3" (see example below). Of course I'm aware that passing a string using PDO::PARAM_INT is wrong, but I'm wondering why there is nothing to be found in the PHP changelog and why there is no exception or warning thrown. Does anyone know if this is a desired behaviour? $sql = "UPDATE test SET name =

Connect PDO with Oracle database

穿精又带淫゛_ 提交于 2021-02-07 03:42:46
问题 I am new to Oracle, installed the Oracle today the 11g Express Edition. Then I installed Java SDK, and then the free Oracle SQL Developer. I connected with system account and created a username and table as defined below. I don't exactly know how Oracle works, I think instead of database name, usernames are used. So below are details. Username/Connection/Database = CustomSearch Table = Reservation_General_2 There are some columns inside that table and some data. but the point is I cant

Connect PDO with Oracle database

邮差的信 提交于 2021-02-07 03:39:06
问题 I am new to Oracle, installed the Oracle today the 11g Express Edition. Then I installed Java SDK, and then the free Oracle SQL Developer. I connected with system account and created a username and table as defined below. I don't exactly know how Oracle works, I think instead of database name, usernames are used. So below are details. Username/Connection/Database = CustomSearch Table = Reservation_General_2 There are some columns inside that table and some data. but the point is I cant