pdo

How to use prepared statements (named parameters) on a php Class

喜夏-厌秋 提交于 2021-02-19 05:34:38
问题 This is my first post here. I've searched in the site, but inforutunaly no matchs. Anyway, i want to know how to use named parameters on a class. so the pdo basic form is something like. $query = $bdd->prepare('SELECT * FROM table WHERE login = :login AND pww = :pww'); $query->execute(array('login' => $login, 'pww' => $pww)); and i want to integrate this on a class regardless of the number of parameters. Currently, i have this code http://pastebin.com/kKgSkaKt and for parameters, i use

MySQL update, skip blank fields with PDO

邮差的信 提交于 2021-02-18 17:09:37
问题 I would like to update a MySQL row via the form below. The form works great as is but, if I leave a field blank, it changes the field in MySQL to blank as well. I would like to update the sql but skip over any fields that are blank. I have read a few ways of doing this but they didn't seem logical. I.e. using if statements in the sql string itself. (Having MySQL do the work that should be done in PHP). if($_SERVER['REQUEST_METHOD'] != 'POST') { echo '<form method="post" action=""> ID: <input

MySQL update, skip blank fields with PDO

我们两清 提交于 2021-02-18 17:09:27
问题 I would like to update a MySQL row via the form below. The form works great as is but, if I leave a field blank, it changes the field in MySQL to blank as well. I would like to update the sql but skip over any fields that are blank. I have read a few ways of doing this but they didn't seem logical. I.e. using if statements in the sql string itself. (Having MySQL do the work that should be done in PHP). if($_SERVER['REQUEST_METHOD'] != 'POST') { echo '<form method="post" action=""> ID: <input

MySQL update, skip blank fields with PDO

Deadly 提交于 2021-02-18 17:07:57
问题 I would like to update a MySQL row via the form below. The form works great as is but, if I leave a field blank, it changes the field in MySQL to blank as well. I would like to update the sql but skip over any fields that are blank. I have read a few ways of doing this but they didn't seem logical. I.e. using if statements in the sql string itself. (Having MySQL do the work that should be done in PHP). if($_SERVER['REQUEST_METHOD'] != 'POST') { echo '<form method="post" action=""> ID: <input

PHP PDO dynamic update query to MYSQL

家住魔仙堡 提交于 2021-02-17 07:08:55
问题 I have a form with an image upload and text inputs. it keeps replacing the profile_picture field with NULL. Therefore, I'm trying to create a dynamic update query, where if one value is empty it's excluded from the query altogether. Any help is appreciated. IMAGE UPLOAD: if (!empty($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] == UPLOAD_ERR_OK) { // Rename the uploaded file $uploadName = $_FILES['profile_picture']['name']; $tmp_name = $_FILES['profile_picture']['tmp_file'

PDO and binding multiple value sets during insert - recently

丶灬走出姿态 提交于 2021-02-17 06:07:27
问题 Using PDO in PHP, when having to insert multiple rows into a table at once, I've used sql that looks something like this: INSERT INTO some_names (firstName, lastName) VALUES ('Joe', 'Smith'),('Fred','Sampson'),('Lisa','Pearce'); As you can see I'm inserting three rows with one statement. The reason I do this is that I believe it is more efficient than executing three distinct statements to insert the rows. So my question is this: how do I do this in PHP if I want to be able to bind my values

PDO and binding multiple value sets during insert - recently

我是研究僧i 提交于 2021-02-17 06:05:44
问题 Using PDO in PHP, when having to insert multiple rows into a table at once, I've used sql that looks something like this: INSERT INTO some_names (firstName, lastName) VALUES ('Joe', 'Smith'),('Fred','Sampson'),('Lisa','Pearce'); As you can see I'm inserting three rows with one statement. The reason I do this is that I believe it is more efficient than executing three distinct statements to insert the rows. So my question is this: how do I do this in PHP if I want to be able to bind my values

'PDOException' Syntax error or access violation: 1064 You have an error in your SQL syntax; check

ぃ、小莉子 提交于 2021-02-16 20:28:48
问题 I keep getting the following error when trying to submit details of an order into my database: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' in /home/ubuntu/workspace/handlers/checkout-handler.php on line 111 PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an

How to print table data index in RecursiveArrayIterator

左心房为你撑大大i 提交于 2021-02-16 18:27:10
问题 I want to print a table with index and I'm currently new to PDO and recursive table printing (is that what it's called?). I found a sample code to do that but it didn't print the index together with the data. So I modified the code to include index. However, I'm using Global Variable and from what I understand, it is a bad practice to use global variable. Is that so? Any other way to do it? <?php echo "<table id='DataTable1' class='display' cellspacing='0' width='100%'>"; echo "<tr><th>No</th

How to print table data index in RecursiveArrayIterator

柔情痞子 提交于 2021-02-16 18:26:25
问题 I want to print a table with index and I'm currently new to PDO and recursive table printing (is that what it's called?). I found a sample code to do that but it didn't print the index together with the data. So I modified the code to include index. However, I'm using Global Variable and from what I understand, it is a bad practice to use global variable. Is that so? Any other way to do it? <?php echo "<table id='DataTable1' class='display' cellspacing='0' width='100%'>"; echo "<tr><th>No</th