pdo

is this dynamic (column & table) PHP select query safe?

我们两清 提交于 2020-01-17 05:33:10
问题 Tables and Columns names cannot be bind using PDO ->bindParam(), but I am sure more than one would love to be able to. It is a little late, but I wrote this earlier and so far it works. I am kind of new to php, and would like to know what you think and if it is safe. $type = "defaultTableName"; $sortBy = "defaultColumnName"; $orderBy = "ASC"; //whitelisting unsafe input if(isset($_GET['orderBy'])&&($_GET['orderBy']=="ASC"||$_GET['orderBy']=="DESC")) $orderBy = $_GET['orderBy']; $tableNames =

What does Apache need to support both mysqli and PDO?

孤街浪徒 提交于 2020-01-17 03:42:09
问题 I'm considering changing some PHP code to use PDO for database access instead of mysqli (because the PDO syntax makes more sense to me and is database-agnostic). To do that, I'd need both methods to work while I'm making the changeover. My problem is this: so far, either one or the other method will crash Apache . Right now I'm using XAMPP in Windows XP, and PHP Version 5.2.8. Mysqli works fine, and so does this: $dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);

MySQL/PHP/PDO + How to get a row for each (duplicate) entry in IN() clasue?

感情迁移 提交于 2020-01-17 01:05:18
问题 Language: PHP DB: MySQL My understanding is that if you have duplicate entries in the IN() clause.. they will be skipped... I need a return/row for each item in the IN() clause.. regardless if they are dups or not. From reading... I believe a [self] JOIN() is the approach/solution I am looking for.. but I am not clear on how to do this JOIN on the same table? .. especially with the query I already have going below. (which works how I need it to.. expect for not returning a row for the

MySQL/PHP/PDO + How to get a row for each (duplicate) entry in IN() clasue?

让人想犯罪 __ 提交于 2020-01-17 01:01:12
问题 Language: PHP DB: MySQL My understanding is that if you have duplicate entries in the IN() clause.. they will be skipped... I need a return/row for each item in the IN() clause.. regardless if they are dups or not. From reading... I believe a [self] JOIN() is the approach/solution I am looking for.. but I am not clear on how to do this JOIN on the same table? .. especially with the query I already have going below. (which works how I need it to.. expect for not returning a row for the

Artisan-commands need different hostname in db-config than Laravel itself

情到浓时终转凉″ 提交于 2020-01-16 18:41:52
问题 This is a strange one I've never been able to solve ever since I started using Laravel. When I issue artisan-commands like 'php artisan migrate' in my db-config (I'm using MySQL via MAMP) the host line has to be: 'host' => 'localhost:8889', However when loading a page in the web-browser I get: SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:8889' It magically works when I change it to: 'host' => 'localhost', On the live-server I'm running the application on I don't have this

Artisan-commands need different hostname in db-config than Laravel itself

夙愿已清 提交于 2020-01-16 18:41:11
问题 This is a strange one I've never been able to solve ever since I started using Laravel. When I issue artisan-commands like 'php artisan migrate' in my db-config (I'm using MySQL via MAMP) the host line has to be: 'host' => 'localhost:8889', However when loading a page in the web-browser I get: SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:8889' It magically works when I change it to: 'host' => 'localhost', On the live-server I'm running the application on I don't have this

How to insert a row and ignore only UNIQUE contraint errors, without using SELECT

感情迁移 提交于 2020-01-16 18:22:12
问题 I have a table with a column that must have UNIQUE values (but it could be also a multiple-column UNIQUE index, the problem is the same). In my PHP script I have to insert a row in that table. I'm searching for a way, not MySQL-specific, to exit the PHP script if there's a problem, and the problem is not a violation of a UNIQUE constraint. To make things more easy I don't want to use a SELECT query before :D Currently I'm doing something like this: try { $stmt = $dbh->prepare($someinsertquery

How to insert a row and ignore only UNIQUE contraint errors, without using SELECT

可紊 提交于 2020-01-16 18:22:10
问题 I have a table with a column that must have UNIQUE values (but it could be also a multiple-column UNIQUE index, the problem is the same). In my PHP script I have to insert a row in that table. I'm searching for a way, not MySQL-specific, to exit the PHP script if there's a problem, and the problem is not a violation of a UNIQUE constraint. To make things more easy I don't want to use a SELECT query before :D Currently I'm doing something like this: try { $stmt = $dbh->prepare($someinsertquery

PDOStatement::fetch occasionally returns false, but errorInfo() is empty

两盒软妹~` 提交于 2020-01-16 15:47:08
问题 I am having strange problem with PDO. Code is like this: $dbh = new PDO($dsn, $user, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { $sth = $dbh->prepare("SELECT ... FROM .... "); $sth->execute(); $result = $sth->fetch(PDO::FETCH_ASSOC); if (!$result) { print_r($dbh->errorInfo()); print_r($sth->errorInfo()); } } catch(PDOException $e) { print_r($e->getMessage()); } So it's very common use of PDO. And the code works as expected most of the time. But

Database, php pdo and html

你离开我真会死。 提交于 2020-01-16 10:13:10
问题 I have been going over the same scenario several times but It just wont work for me regardless of what I do. What I am trying to do is update my website content straight from my database. I have tables that correspond to my tables in my webpage and I want to simply outut the results. This is how It looks right nw <?php $file = dirname(__FILE__) . "/db.sqlite"; $db = new PDO("sqlite:$file"); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); ?> <div class="featured"> <h3>Featured</h3>