pdo

PHP/PDO/MySQL: Convert Multiple Queries Into Single Query

馋奶兔 提交于 2020-01-06 04:25:07
问题 (Yes, I have "thoroughly searched for an answer before asking my question"... but haven't found the "right" answer to my issue. I have read the MySQL man about user variables... I have read the PHP man regarding PDO... still can't grok the solution.) I'm trying to get from PHP code the same result set returned from this SQL statement that executes correctly and successfully within PhpMyAdmin: SET @x := 0; SELECT * FROM ( SELECT `o`.`timestamp` `o`.`v_phase_a` , `o`.`v_phase_b` , `o`.`v_phase

Simple PDO Wrapper not working

早过忘川 提交于 2020-01-06 04:18:13
问题 I'm trying out this Wrapper and no matter what I always just get 'boolean false' when I var_dump($row) in my index.php file. Here is my db class: <?php // database.php class DB { protected $_connection = array(); // to map the connection protected $_dbh; // property which keeps the database handler protected $_database; // property to keep the database name protected $_table; // property to keep the table name protected $_query; // property to keep a query statement public function _

Prevent auto increment on duplicate entry

一世执手 提交于 2020-01-06 03:36:14
问题 I have seen this issue around (See links at bottom) but I can't seem to figure out an answer. The problem is that I insert data on a table with an auto increment ID that is a primary key, and another field with a UNIQUE index to avoid duplicates. This works, but when that happens the ID is incremented, although no data has been stored. Would it be better to remove the auto increment, and handle it myself, selecting the max(ID)? At the moment I have tried several strategies to make it work as

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

我是研究僧i 提交于 2020-01-06 03:00:07
问题 My code produces the error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens But I counted, there are no missing colons and all the binding parameters are there... What is causing this error? Reference the Code Below: try{ $pdo->beginTransaction(); $insert1 = $pdo->prepare("INSERT INTO spo (spo_prefix,datecreated,destinationID,vendorID,grade,flute,qty,wdat,ldat,scoreline,due,remark,isowarrant,area_m,area_ft,supplyIDs,qty_waste,expectedPrice)

Update select list without refresh [PDO/PHP/AJAX]

非 Y 不嫁゛ 提交于 2020-01-05 21:06:12
问题 I'm using bootstrap and i've created teo tabs that insert data into database, but the first tab have a selection list that loads data inserted using the form in the second tab. The problem is that i can't fill the selection list in the first tab without refreshing the page. I've tried inumerous solutions here in stackoverflow and googling but no one worked. Here is the code of the form and php: <form class='form-horizontal' role='form' action="index.php" method="post" id="nl_0" name="nl_0">

Is it possible to use both MySQLi and PDO?

送分小仙女□ 提交于 2020-01-05 17:57:15
问题 Is it possible to use both MySQLi and PDO ? For example, to insert data using MySQLi and then select and work with it using PDO in other part of the project? I have a lot of insert/update code in MySQLi, but decided to switch to PDO? 回答1: Yes, it's possible. But keep in mind that you'd have two completely separated connections to the MySQL server in any case. The mysqli_* and PDO_MySQL extensions cannot (currently) share a single connection even though they use the same transport driver

How to use prepared statements in this query?

纵然是瞬间 提交于 2020-01-05 13:13:06
问题 I'm new to PHP and PDO, and I try to use prepared statements here. After 1 hour of trying around I give up. Or my tutorial was just horribly bad. EDIT: This works perfectly without prepared statements: try { $dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'root'); $prepared = $dbh->prepare('SELECT * from sys_navigation_point WHERE name="root"'); //$prepared->bindParam('foo', 'root'); $prepared->execute(); foreach($prepared as $row) { print_r($row); } $dbh = null; } catch

PHP: Injection protection using prepared statements

让人想犯罪 __ 提交于 2020-01-05 11:02:36
问题 I am familiar with using PHP to perform mySQL queries. However, I have been using reg exps as protection against injection attacks. After reading several questions/answers here on SO, I've decided to opt for prepared statements instead. There's two options available (let me know if there are more): mysqli prepared statements PDO prepared staments Question 1 I am trying to understand the code examples given on the linked pages. For mysqli , Example #1 : if ($stmt = $mysqli->prepare("SELECT

PHP: Injection protection using prepared statements

别等时光非礼了梦想. 提交于 2020-01-05 11:02:20
问题 I am familiar with using PHP to perform mySQL queries. However, I have been using reg exps as protection against injection attacks. After reading several questions/answers here on SO, I've decided to opt for prepared statements instead. There's two options available (let me know if there are more): mysqli prepared statements PDO prepared staments Question 1 I am trying to understand the code examples given on the linked pages. For mysqli , Example #1 : if ($stmt = $mysqli->prepare("SELECT

How to convert PDO to mysqli?

喜欢而已 提交于 2020-01-05 10:24:13
问题 I have a login screen in which the user inputs their username and password. I managed to connect to the database using PDO but I have to change it to mysqli. Could someone please help me convert it to mysqli. Thanks in advance. PDO: <?php try { $database = new PDO('mysql:host=localhost;dbname=myfiles', 'root', '',array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $query = "SELECT * FROM users WHERE Username = ? AND Password = ?"; $userParam = array($_POST["Uname"], $_POST["Pass"]); $st =