pdo

PDO prepared statement fetch() returning double results

扶醉桌前 提交于 2019-12-29 01:34:14
问题 I have a script that is outputting to a CSV file. However, even though there is currently one row in the database, the output I'm getting is echoing out each column from each row in the table twice. For example: 1,1,John,John,Smith,Smith,2014,2014 Should be 1,John,Smith,2014 This worked fine before I went with PDO and prepared statements, so I'm thinking maybe I'm not understanding how fetch() works correctly. Below is my code. Any idea what I could be doing wrong? // get rows $query_get_rows

PHP generate dynamic PDO insert

时光毁灭记忆、已成空白 提交于 2019-12-29 00:41:14
问题 The following code should insert each key-value pair in an array into a mathing column-value in a table. The script returns no errors but the the inserted row contains only the last value in the array E.g. array('one'=>1,'two'=>2,'three'=>3); insert the row successfully in a table with columns one, two and three but insert the value 3 in all. $columns = array(); $bind = ''; foreach($array as $key => $value){ $columns[] = $key; } $columnString = implode($columns,','); $valueString = implode(

How do i Insert Multiple records in one database trip using PDO?

孤者浪人 提交于 2019-12-29 00:22:48
问题 i have a table called propAmenities which holds two column amenity_id and property_id basically the table holds the foreign keys. now i have to generate a PDO query using named placeholder for the below statement. INSERT INTO propAmenities (amenity_id, property_id) VALUES (1, 1), (2, 1), (3, 1) i tried using the following syntax but i am not sure if this will work. $sth->$this->dbh->prepare('INSERT INTO propAmenities (amenity_id, property_id) VALUES (:amenity_id, :property_id), (:amenity_id,

How do I demonstrate a Second Order SQL Injection?

∥☆過路亽.° 提交于 2019-12-28 18:23:17
问题 So I've been trying to replicate a second order SQL Injection. Here's an example template of two php based sites that I've prepared. Let's just call it a voter registration form. A user can register and then you can check if you're a registered voter or not. insert.php <?php $db_selected = mysql_select_db('canada',$conn); if (!db_selected) die("can't use mysql: ". mysql_error()); $sql_statement = "INSERT into canada (UserID,FirstName,LastName,Age,State,Town) values ('".mysql_real_escape

PHP PDO-MYSQL : How to use database connection across different classes

江枫思渺然 提交于 2019-12-28 13:57:09
问题 I'm kinda new to PDO with MYSQL, here are my two files: I have a connection class that I use to connect to the database: class connection{ private $host = 'localhost'; private $dbname = 'devac'; private $username = 'root'; private $password =''; public $con = ''; function __construct(){ $this->connect(); } function connect(){ try{ $this->con = new PDO("mysql:host=$this->host;dbname=$this->dbname",$this->username, $this->password); $this->con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE

SQL Select * from multiple tables

久未见 提交于 2019-12-28 12:30:10
问题 Using PHP/PDO/MySQL is it possible to use a wildcard for the columns when a select is done on multiple tables and the returned array keys are fully qualified to avoid column name clash? example: SELECT * from table1, table2; gives: Array keys are 'table1.id', 'table2.id', 'table1.name' etc. I tried "SELECT table1.*,table2.* ..." but the returned array keys were not fully qualified so columns with the same name clashed and were overwritten. 回答1: Yes, you can. The easiest way is with pdo,

How to insert point data into mysql using PDO bindParam?

与世无争的帅哥 提交于 2019-12-28 07:05:10
问题 DETAILS I'd like to make use of mysql's spatial extension, so I am trying to store longitude and latitude in a mysql table of datatype POINT using bindParam. Unfortunately, I keep getting the error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'location' cannot be null. I've checked that longitude and latitude have values. So the problem has to be with my code, but I cannot see what I am doing wrong. Here is the code I am using. $location=$latitude." ".$longitude; $sql =

How to insert point data into mysql using PDO bindParam?

时光毁灭记忆、已成空白 提交于 2019-12-28 07:05:08
问题 DETAILS I'd like to make use of mysql's spatial extension, so I am trying to store longitude and latitude in a mysql table of datatype POINT using bindParam. Unfortunately, I keep getting the error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'location' cannot be null. I've checked that longitude and latitude have values. So the problem has to be with my code, but I cannot see what I am doing wrong. Here is the code I am using. $location=$latitude." ".$longitude; $sql =

PHP - How to install PDO driver? (Windows)

安稳与你 提交于 2019-12-28 06:57:25
问题 I am setting up PHP and MySQL (Maria DB) on Windows 8.1. I edited php.ini file and uncommented the following lines: extension=php_mysql.dll extension=php_mysqli.dll extension=php_pdo_mysql.dll But unfortunately I cannot connect to database because there are no pdo drivers shown in phpinfo output. So, when I try to establish database connection, an exception is thrown: Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' How can this problem be solved? 回答1:

Is a BLOB converted using the current/default charset in MySQL?

家住魔仙堡 提交于 2019-12-28 06:49:05
问题 I have a table with a BLOB field. The charset of the table is Latin1. I connect to the DB and "SET CHARACTER SET utf8". Then I save binary data into the field. Then I retrieve the data, and it's not what I saved (corrupt). The code: <?php $pdo = new \PDO("mysql:host=127.0.0.1;dbname=***", '***', '***'); $pdo->exec('SET CHARACTER SET utf8'); $sql = "INSERT INTO pdo_blob (the_blob) VALUES(:the_blob)"; $insertStm = $pdo->prepare($sql); $blob = (binary) file_get_contents('/home/***/test.pdf');