pdo

PHP PDO Database Error Special Characters

邮差的信 提交于 2019-12-25 02:59:39
问题 i've read most of the questions and answers about this situation but i cant fix my character problem. My database's default character set is utf8 and all the tables' collation is utf8_general_ci. I'm sure that all of the settings are utf8 and utf8_general_ci, cuz i've checked them billions of time. Problem is after posting the value within a form, it doesnt seem like what i want in database, and also if i edit the database from phpmyadmin, when i fetch the data, its again not showing what i

pdo insert two rows when I wanna insert only one

坚强是说给别人听的谎言 提交于 2019-12-25 02:47:21
问题 I have a problem, I'm using pdo for make queries in my mysql database. When I want make an insert in my table of only one record, this insert TWO rows.. I dont know why insert two when this should insert only one. This is the php code: <?php $db = new PDO("mysql:host=localhost;dbname=mydatabase", "root", ""); $sql = "INSERT INTO test(lala)VALUES('xx1')"; $db->query($sql); ?> 回答1: Check HTTP requests. Most likely your code acts as a 404 handler and there is an extra request from browser. 来源:

Referencing to an associative array value from PDO::FETCH_ASSOC

若如初见. 提交于 2019-12-25 02:44:58
问题 Im having a very basic problem using PDO and i need some help - chances are I have a syntax error somewhere but i cant for the life of me find it (im new to PDO and havent used associative arrays very much so focus on this part of the code!) I am selecting all the data from my database associated with a user with a certain email address using the following code: $id = 'email@address.com'; $stmt = $db->prepare('SELECT * FROM first_page WHERE email=?'); $stmt->bindValue(1, $id, PDO::PARAM_STR);

PHP/MYSQL Retrieve Name based on another criterion

南楼画角 提交于 2019-12-25 02:25:33
问题 So I have a login system and I want to retrieve the first name of the person who is logged in. Here's my php: function verify_Username_and_Pass($un, $pwd) { $query = "SELECT `First Name`, Username, Password FROM table WHERE Username = :un AND Password = :pwd LIMIT 1"; $stmt = $this->conn->prepare($query); $stmt->bindParam(':un', $un); $stmt->bindParam(':pwd', $pwd); $stmt->execute(); if ($stmt->rowCount() > 0) { // User exist return true; $stmt->close(); } else { // User doesn't exist return

PDO if fetch() then print_r($smt->fetch(PDO::FETCH_OBJ)) wont show any result

泄露秘密 提交于 2019-12-25 02:25:26
问题 I have a login database with user and password and a html file with input type for username and password.. in my class for the login: class login { protected $_username; protected $_password; public function __construct($username, $password) //$username and $password values will be from the $_POST['username and password'] when the user submits the username and password { $this->username = $username; $this->password = md5($password); } public function login() { try { $pdo = dbConnect:

How to pass an integer to a query in CakePHP?

六眼飞鱼酱① 提交于 2019-12-25 02:11:10
问题 Edit 1: this is not about LIMIT , this is about passing an integer. Other function that requires to pass numbers is IN Edit 2: Should I use PDO::PARAM_INT ? When I do this: $query .= ' LIMIT ? , ? '; $values [] = $offset ; $values [] = $rows ; At this line: $db->fetchAll ( $query , $values); Instead of execute: SELECT ....... LIMIT 0 , 10; It tries to execute: SELECT ....... LIMIT '0' , '10'; Causing an error: Error Code: 1064. You have an error in your SQL syntax; check the manual that

PHP display results equivalent to comma separated values in the database

别说谁变了你拦得住时间么 提交于 2019-12-25 01:48:46
问题 I have a database structure say this: table: advertisements ad_id | ad_memberships 1 | 1,2 2 | 1,2,3 3 | 1,3 4 | 2,3 table: memberships mbs_id | mbs_color 1 | red 2 | yellow 3 | green I want to display the colors for the values that are there in ad_memberships field. This field contains the IDs from memberships tables which is mbs_id . Now since ad_memberships contains 1,2 then the red and yellow color should be displayed. If it contains 1,3 or 2,3 or 1,2,3 then red, green or yellow, green or

PHP PDO binding variables to a string while concatenating it

∥☆過路亽.° 提交于 2019-12-25 01:46:03
问题 I'm trying to create an SQL statement which looks something like this: SELECT * FROM `table` WHERE `attribute` LIKE %variable_1% AND `attribute` LIKE %variable_2% AND ... AND `attribute` LIKE %variable_n% I have the variables : variable_1, variable_2, ... ,variable_n stored in an array and in order to create the statement mentioned above I'm gonna use a foreach loop, like so: $sql = 'SELECT * FROM `table` WHERE '; $variables_array; // this array will contain all the variables mentioned above,

PHP MySQL PDO -> ON INSERT if value already there do another query

半世苍凉 提交于 2019-12-25 01:44:52
问题 I have a mysql db with two tables. The first table is called 'uniqueReferences' and the second one 'duplicatedReferences'. The two tables have two fields only: an id field (auto-incremented) and a field called Reference. What I would like is as follows. When trying to insert a ref in the 'uniqueReferences' table, if the reference already exists, do not insert it in that table but in the table 'duplicatedReferences'. So what I tried but did not work is the following. 1-> set the field

Not able to update rows using PDO

不打扰是莪最后的温柔 提交于 2019-12-25 01:43:52
问题 When I run the following code: // Loop through each store and update shopping mall ID protected function associateShmallToStore($stores, $shmall_id) { foreach($stores as $store_id) { $sql .= 'UPDATE my_table SET fk_shmallID = :shmall_id WHERE id = :store_id'; $stmt = $this->db->prepare($sql); $stmt->bindParam(':shmall_id', $shmall_id); $stmt->bindParam(':store_id', $store_id); $stmt->execute(); } } I get the following message: Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE