pdo

PHP - Variables not replaced in PDO connection string

痴心易碎 提交于 2019-12-24 18:15:10
问题 Strange issue - I have a live copy of a database class (using PDO) that works fine. I have a copy on my machine using WAMPServer which does not. The connection string is as follows (a snippet from the class): $host = 'localhost'; $user = 'user'; $pass = 'password'; $dbname = 'my_dbname'; self::$_instance = new PDO('mysql:host=$host;dbname=$dbname', $user, $pass); The error messages I get are: Warning: PDO::__construct() [pdo.--construct]: php_network_getaddresses: getaddrinfo failed: No such

My PDO Statement doesn't work

此生再无相见时 提交于 2019-12-24 18:11:16
问题 This is my PHP sql statement and it's returning false while var dumping $password_md5 = md5($_GET['password']); $sql = $dbh->prepare('INSERT INTO users(full_name, e_mail, username, password, password_plain) VALUES (:fullname, :email, :username, :password, :password_plain)'); $result = $sql->execute(array( ':fullname' => $_GET['fullname'], ':email' => $_GET['email'], ':username' => $_GET['username'], ':password' => $password_md5, ':password_plain' => $_GET['password'])); 回答1: Sometimes your

Globally disable all MySQL writes

為{幸葍}努か 提交于 2019-12-24 18:06:08
问题 I am using PHP's PDO with MySQL to create a web application. I wish to put the web application in "demo" mode. What this means is all writes (updates, inserts, deletes) are disabled, and the applicable continues with out any errors. For arguments sake, the application is in demo mode if $_SESSION['demo_mode']=1. Without putting conditionals around each write statement, how can this be done. $dbh->exec("INSERT INTO t1(c1, c2) VALUES ('v1', 'v2')"); $dbh->lastInsertId(); $q=$dbh->query("SELECT

Globally disable all MySQL writes

≯℡__Kan透↙ 提交于 2019-12-24 18:06:05
问题 I am using PHP's PDO with MySQL to create a web application. I wish to put the web application in "demo" mode. What this means is all writes (updates, inserts, deletes) are disabled, and the applicable continues with out any errors. For arguments sake, the application is in demo mode if $_SESSION['demo_mode']=1. Without putting conditionals around each write statement, how can this be done. $dbh->exec("INSERT INTO t1(c1, c2) VALUES ('v1', 'v2')"); $dbh->lastInsertId(); $q=$dbh->query("SELECT

PDO cannot compare mysql ENUM using integers in prepared statements

十年热恋 提交于 2019-12-24 17:02:16
问题 I am using PDO and prepared statements, but i cannot seem to get any results when comparing an ENUM field with an integer . Example: $db = new PDO('mysql:host=localhost;dbname=****', '***', '***'); $s = $db->prepare('SELECT id FROM t2 WHERE lang = ?'); $s->execute(array('en')); // Works print_r($s->fetchAll()); $s->execute(array(2)); // Does not work print_r($s->fetchAll()); I Am testing against this table: DROP TABLE IF EXISTS t2; CREATE TABLE t2 ( id int(10) NOT NULL AUTO_INCREMENT, lang

PHP PDO with SqlServer Stored Procedure doesn't return all the data

淺唱寂寞╮ 提交于 2019-12-24 16:43:14
问题 I've been given an stored procedure that is called like this: SP_REPORT_HOME 'param1','param2',1 It executes a bunch of code i'm not aware of, although it return a bunch of data I need to use. It contains some fields with null values, while others are fully filled (note that the entire row is not null, only some fields) Well I'm using PDO and PHP on an Ubuntu 10.10 machine to get that information, my getReport method is: public function getReport($empresa1, $empresa2, $num) { $ds = $this-

PHP PDO with SqlServer Stored Procedure doesn't return all the data

大憨熊 提交于 2019-12-24 16:43:01
问题 I've been given an stored procedure that is called like this: SP_REPORT_HOME 'param1','param2',1 It executes a bunch of code i'm not aware of, although it return a bunch of data I need to use. It contains some fields with null values, while others are fully filled (note that the entire row is not null, only some fields) Well I'm using PDO and PHP on an Ubuntu 10.10 machine to get that information, my getReport method is: public function getReport($empresa1, $empresa2, $num) { $ds = $this-

How can I return LastInsertID from PDO whin a method of a class

前提是你 提交于 2019-12-24 16:34:06
问题 I have create a small class that handles my MySql queries. However, Now I am trying to get the value of the last inserted id but it is not wokring for me if my processQuery method in the class I do a prepare statement with any query like insert/update/remove I have added this line $this->lastInsertId = $this->pdo->lastInsertId; which should give me the last inserted Id and stores it in the public variable called $lastInsertId then I can access it from my code outside. How can I get the last

PDO fetching the next row of database row by row

為{幸葍}努か 提交于 2019-12-24 16:22:27
问题 is there any way to fetch the next row from the database row by row using PDO?? i'm trying to fetch the next row of data when i click the next button and this is my code : if($typeuser == 'admin'){ $dta = new PDO('mysql:host=localhost;dbname=laundry','root',''); $sta = $dta->prepare("SELECT * FROM konsumen"); $sta->execute(); $rowa = $sta->fetch(); $kode_pemesanan = $rowa['kode_pemesanan']; $atas_nama = $rowa['atas_nama']; $jmlhbaju = $rowa['jmlhbaju']; $jmlhcelana = $rowa['jmlhcelana'];

Displaying data from a database using PDO

混江龙づ霸主 提交于 2019-12-24 15:21:24
问题 I've been staring at code for hours trying to see what I'm missing. Maybe someone can point me in the right direction. First I have a database with multiple tables. One for images that stores the location and details of products. I've built pages that let me view, edit and add products. This all works great. I'm now trying to do something simple and its not working. I created a table "Contacts" in the database and added the rows "name, street, city, zip, phone, email". I have populated this