pdo

Search using REPLACE in a SELECT with PDO and .MDB ACCESS, with PHP

萝らか妹 提交于 2021-01-28 03:51:54
问题 I'm trying to write a mysql query that will match names from a table and the name in the database can contain dots or no dots. So, for example I would like my query string fast to match all of these: fast , f.ast , f.a.s.t etc. I use PHP, with PDO connecting to a .MDB database. I tried what I found here, with no success (I get error): SELECT * FROM table WHERE replace(col_name, '.', '') LIKE "%fast%" I think PDO for MDB databases is missing some functions :( Any solution? 回答1: Thanks to Doug,

construct conditional SQL statement with PDO

99封情书 提交于 2021-01-28 03:14:39
问题 what is the best way to construct an SQL statement with PDO when it depends on whether some PHP variable are set? Here is an example; $query="SELECT * FROM table "; if($variable1 != "") { $query = $query . "WHERE variable1 = :variable1"; } if($variable2 != "") { $query = $query . " AND variable2 = :variable2"; } $query -> execute(array(':variable1' => $variable1, ':variable2' => $variable2)); I have a lot of these if statements and when binding the variables to the query I don't want to go

Dynamically update dropdown based on previous selection with PHP PDO

穿精又带淫゛_ 提交于 2021-01-07 06:21:56
问题 This has been answered before, however I'm asking again for two reasons: I can't find any resources that utilize PDO, and regardless of that, all of the ones I've found consist of code without any comments or explanations, which makes it hard to interpret and adapt them to my use case. I need to be able to make a dropdown dynamically update itself based on the selection of the previous one, and if I change that selection, it should re-update itself without having to submit the form or reload

Dynamically update dropdown based on previous selection with PHP PDO

て烟熏妆下的殇ゞ 提交于 2021-01-07 06:15:39
问题 This has been answered before, however I'm asking again for two reasons: I can't find any resources that utilize PDO, and regardless of that, all of the ones I've found consist of code without any comments or explanations, which makes it hard to interpret and adapt them to my use case. I need to be able to make a dropdown dynamically update itself based on the selection of the previous one, and if I change that selection, it should re-update itself without having to submit the form or reload

PHP - Check if row exists before inserting

爷,独闯天下 提交于 2020-12-31 09:48:28
问题 $DBH = new PDO($dsn, $username, $password, $opt); $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $DBH->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $STH = $DBH->prepare("INSERT INTO requests (id,imdbid,msg) VALUES ('',:imdbid,:msg)"); $STH->bindParam(':imdbid', $_POST['imdbid']); $STH->bindParam(':msg', $_POST['msg']); $STH->execute(); echo "<p>Successfully Requested ".$_POST['imdbid']."! Thanks!</p>"; Is there either some SQL Query that will check and insert or what? I

PDO not throwing exception with unbound parameters (and no variables in query)

左心房为你撑大大i 提交于 2020-12-30 06:41:32
问题 So I have no idea what's going on here $link = new PDO('pgsql:dbname=' . $name . ';host=' . $host, $user, $password); $link->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { $stmt = $link->prepare("SELECT s.*, d.invalid_column FROM students s ORDER BY s.student_id"); $stmt->execute(array(1)); } catch (PDOException $e) { print $e->getMessage(); } When I run this little code example, I expect an exception to be thrown (as d

PDO not throwing exception with unbound parameters (and no variables in query)

北慕城南 提交于 2020-12-30 06:39:33
问题 So I have no idea what's going on here $link = new PDO('pgsql:dbname=' . $name . ';host=' . $host, $user, $password); $link->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { $stmt = $link->prepare("SELECT s.*, d.invalid_column FROM students s ORDER BY s.student_id"); $stmt->execute(array(1)); } catch (PDOException $e) { print $e->getMessage(); } When I run this little code example, I expect an exception to be thrown (as d

PHP PDO Fatal error: Call to a member function prepare() on null

末鹿安然 提交于 2020-12-26 05:15:25
问题 trying to learn the ins and outs of PDO and I just got into this brick wall. My current PDO class is the following: class SimpleDatabase extends PDO { const DB_HOST='localhost'; const DB_USER='claudio'; const DB_PASS='claudio'; const DB_NAME='simpledb'; private $dbh; private $error; private $stmt; public function __construct(){ // Set DSN $dsn = 'mysql:host=' . self::DB_HOST . ';dbname=' . self::DB_NAME; // Set options $options = array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO:

MySQL PDO Name-Value Prepared Statement Using Last Parameter Only

丶灬走出姿态 提交于 2020-12-23 12:22:48
问题 As titled, I'm using MySQL PDO with a prepared statement, and when executing, I'm getting a single value (the last supplied value) pushed into all fields. Table looks like so: id (int - auto-increment) a_id (int) b_id (int) INSERT looks like this: INSERT INTO my_table(a_id, b_id) VALUES (:a_id, :b_id) Code to insert looks like this... $stmt = $conn->prepare($sql); foreach($params as $k => $v) { $stmt->bindParam( $k, $v ); } $stmt->execute(); The statement successfully inserts a value (which

MySQL PDO Name-Value Prepared Statement Using Last Parameter Only

旧时模样 提交于 2020-12-23 12:20:45
问题 As titled, I'm using MySQL PDO with a prepared statement, and when executing, I'm getting a single value (the last supplied value) pushed into all fields. Table looks like so: id (int - auto-increment) a_id (int) b_id (int) INSERT looks like this: INSERT INTO my_table(a_id, b_id) VALUES (:a_id, :b_id) Code to insert looks like this... $stmt = $conn->prepare($sql); foreach($params as $k => $v) { $stmt->bindParam( $k, $v ); } $stmt->execute(); The statement successfully inserts a value (which