pdo

pdo bind variables to prepared mysql statement and fetch using while loop to display in table

ぃ、小莉子 提交于 2020-01-06 08:25:08
问题 I I am getting myself tangled with a pdo statement to display MySQL data in a table using pdo. my syntax is: $startdate=$_POST["start"]; $enddate=$_POST["end"]; $ttype=$_POST["ttype"]; $result = $db->query("SELECT cycletype,commenttype,adminstatus FROM v2loads where haulier= :haulier and :start < sarrive and :end> sarrive order by sarrive"); $result->bindParam(':haulier', $company, PDO::PARAM_STR); $result->bindParam(':start', $startdate, PDO::PARAM_STR); $result->bindParam(':end', $enddate,

Sql show data in tables without specifying the colum name

限于喜欢 提交于 2020-01-06 08:07:29
问题 So I have this code: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include "../includes/db_conn.php"; $data = $_POST['tabledb']; $sfm = $dbm->prepare('SELECT * FROM '.$data.''); $sfm->execute(); $all = $sfm->fetchAll(); ?> <!DOCTYPE html> <html> <body> <?php foreach ($all as $row) { echo "<option value=\"info\">" . $row[0] . "</option>"; } ?> </body> </html> oke a littel context if have a dropdown menu where you can select rows from the

pdo_sqlsrv: how to recognize if fetch “false” is an error or empty recordset?

寵の児 提交于 2020-01-06 07:10:19
问题 The fetch method returns false both if the recordset is empty and if there is an actual error. The method described here allows you to easily recognize what is happening: ensure that PDO fetch method result "false" is a error or empty result It works well with pdo_mysql, however pdo_sqlsrv throws an error even when the recordset is empty. Is this the intended behaviour? Is it possible to avoid those errors? EDIT: the error is "There are no more rows in the active result set" and it is

using bindParam with PDO

南笙酒味 提交于 2020-01-06 07:07:50
问题 I've been scratching my head over this code for a couple of hours.... Doesn't make sense to me why it doesn't work $isCorrect =($question->correct_answer == $body->answer) ? 1:0; // the values are all there....... // echo $body->question . "\n"; //335 // echo $body->user . "\n"; //51324123 // echo $question->day . "\n"; //0 // echo $isCorrect . "\n"; //0 //but still the below part fails. $db = getConnection(); $sql = "INSERT INTO `answers` (`id`, `question_id`, `user`, `day`, `is_correct`)

Warning: PDO::prepare(): SQLSTATE[42000]: Syntax error or access violation: 1064 when update

橙三吉。 提交于 2020-01-06 06:50:46
问题 I want to update several tables as below: for ($i=0; $i <count($tablesnames); $i++) { $update3=$pdo->prepare('UPDATE :surveytable SET `postrecords`=:newrecord WHERE `id`=:id'); //var_dump()here $update3->bindValue(':surveytable', $tablesnames[$i],PDO::PARAM_STR); $update3->bindValue(':newrecord',$newrecord,PDO::PARAM_STR); $update3->bindValue(':id',$id,PDO::PARAM_INT); $update3->execute(); } Check the var_dump result, $tablesnames[$i] and $newrecord are string , $id is int , $update3 is false

Warning: PDO::prepare(): SQLSTATE[42000]: Syntax error or access violation: 1064 when update

。_饼干妹妹 提交于 2020-01-06 06:50:00
问题 I want to update several tables as below: for ($i=0; $i <count($tablesnames); $i++) { $update3=$pdo->prepare('UPDATE :surveytable SET `postrecords`=:newrecord WHERE `id`=:id'); //var_dump()here $update3->bindValue(':surveytable', $tablesnames[$i],PDO::PARAM_STR); $update3->bindValue(':newrecord',$newrecord,PDO::PARAM_STR); $update3->bindValue(':id',$id,PDO::PARAM_INT); $update3->execute(); } Check the var_dump result, $tablesnames[$i] and $newrecord are string , $id is int , $update3 is false

PDO binding fails with PostgreSQL window function parameters

微笑、不失礼 提交于 2020-01-06 06:11:22
问题 I have to perform a SELECT query on a PostgreSQL database usign the OVER() window function. It allows to get either the range of selected rows specified through the OFFSET and LIMIT values, or the number of total rows the query would get without the limit: SELECT DISTINCT *, COUNT(id) OVER() AS results_num FROM ( SELECT id, name, surname FROM users WHERE children > 1 ORDER BY id ) AS x OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY; To develop a paging method I need to set offset and limit dynamically

How to update MySQL Rows using PHP PDO Prepared Statements

隐身守侯 提交于 2020-01-06 05:26:37
问题 This is how I am receving data from a page: $response = file_get_contents("https://api.themoviedb.org/3/movie/550?api_key=xxxxxx"); if ($response != FALSE) { $response = json_decode($response, true); } And here is an example of what is inside the page: { "genres": [ { "name": "Action" }, { "name": "Adventure" }, { "name": "Science Fiction" } ] } Here is how, I Insert the data $stmt = $conn->prepare("UPDATE genres SET genres_name = :genres_name WHERE tmdb_id = :tmdb_id"); $stmt->bindParam('

PHP docker pdo_mysql driver not found

你。 提交于 2020-01-06 04:36:29
问题 Im trying create a dev environment with php7.1 docker. And no matter what I try for some reason it says "An exception occured in driver: could not find driver ". I have searched through a lot of posts but have found no answer that solves my problem. I am using the following dockerfile and docker-compose.yml: FROM php:7.1-apache COPY dockerConfig/php.ini /usr/local/etc/php/ RUN apt-get update \ && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev \ && docker-php-ext

PDO and caching, how to implement it in a database class?

痴心易碎 提交于 2020-01-06 04:36:14
问题 When using PDO and MySQL, is there any benefit in caching results that I know I am going to be using multiple times on the same page? Or does PDO / MySQL automatically handle this sort of thing? And if I should do it myself, should I store the actual results from a query, or could I just store the PDOStatements in a cache and reuse them? Of course I could store any result I know I'm going to use multiple times on a page in a variable, but it just seems cleaner to let my database class handle