pdo

PDO returns integer columns as String in PHP5.4

别说谁变了你拦得住时间么 提交于 2019-12-30 17:27:07
问题 First of all, I am aware that there are various similar questions on SO such as this and this. However, when I fetch values from a table, integers are always fetched as string. I am using PHP5.4 (5.4.16-1~dotdeb.1) and MYSQL5.5 (5.5.31+dfsg-0+wheezy1). It is written here that MySQL Native Driver is enabled by default in PHP5.4.0. But I still get string values. I initialize a PDO object as follows. try { $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8'; $db = new PDO(

PHP PDO bindParam for variable/string used for “IN” statement…? [duplicate]

試著忘記壹切 提交于 2019-12-30 13:31:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: PHP PDO: Can I bind an array to an IN() condition? Alright, this is really bothering me. How can I bind a paramater (which has multiple values) for an SQL "IN" statment in PHP's PDO? Here are the basics... $allow = "'red', 'blue'"; SELECT * FROM colors WHERE type IN (:allow); $stmt->bindParam(':allow', $allow); This works fine when I plug in $allow by itself, but when trying to bind it and use :allow it fails to

pass constructor arguments using PDO::FETCH_CLASSTYPE

非 Y 不嫁゛ 提交于 2019-12-30 11:51:49
问题 I am replacing my old database layer by a new PDO based version. However i have run into a problem: When fetching objects using fetchObject i can pass arguments for the object constructor. However i am now porting over a class which has several subclasses, all stored in the same table, and i want to use FETCH_CLASSTYPE . This means that i have to use the regular fetch() method to which i cant pass constructor arguments. Is there another way to do this? I could rename the constructor to

How do I parse object data from MySQL database using PHP PDO?

五迷三道 提交于 2019-12-30 11:12:41
问题 I have run into an issue while trying to return object data from my database. I followed this tutorial to build a DB wrapper and have been trying to extend the functionality of it to suit my needs. My problem is that when I use the DB class "get" method to return data, it also returns an instance of the PDO object itself. I am wondering how I parse this data so that I only return objects from the database, and not the database object itself. I want to be able to display different database

How do I parse object data from MySQL database using PHP PDO?

北城余情 提交于 2019-12-30 11:12:00
问题 I have run into an issue while trying to return object data from my database. I followed this tutorial to build a DB wrapper and have been trying to extend the functionality of it to suit my needs. My problem is that when I use the DB class "get" method to return data, it also returns an instance of the PDO object itself. I am wondering how I parse this data so that I only return objects from the database, and not the database object itself. I want to be able to display different database

php white screen of death

江枫思渺然 提交于 2019-12-30 10:07:31
问题 I have browsed several other questions, and tried various solutions related to error reporting, including ini_set('display_errors',true); error_reporting(E_ALL); but I am still stuck with the white screen of death. This seems to happen only on pages when I use my own object oriented classes. However, the OOP scripts execute successfully, but I am unable to get the HTML to show. Occasionally, I can get it to catch an Exception but it is intermittent. For example, I have a this method: public

Uncaught exception 'PDOException' with message 'There is no active transaction'?

只谈情不闲聊 提交于 2019-12-30 09:53:19
问题 This is the code i use to insert record. Whenever there is insert error , The subscriber table auto - inc number will still increase even i have roll back? What is the problem? I just want the auto increment number not add when error occur .thanks a lot for help . $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); $conn->beginTransaction(); try { $email = $_POST['Email']; $FirstName = $_POST['FirstName']; $LastName = $_POST[

underscore in php db variable causing problems

孤者浪人 提交于 2019-12-30 09:32:46
问题 I store all of my login information for databases in files outside of the public tree in variables such as $hostname = '172.0.0.0'; $dbname = 'myname_mydbname'; $username = 'myname_user'; $pw = 'password'; That's pretty standard. The problem is that this particular hosting I am working with requires the myname_ to be appended to the front of all databases and user names. When I store these strings and pass them to a PDO it drops everything in the username after myname, and drops the password

PHP/PDO: How to get the current connection status

纵然是瞬间 提交于 2019-12-30 08:13:54
问题 What is the PDO equivalent of: mysqli_stat($dbConn); P.S. I use it to (get a message to) make sure I am connected 回答1: I cannot get credit for this answer. Someone posted the answer, but he/she latter deleted the entry. Here's the (saved archived) answer to your question: $status = $conn->getAttribute(PDO::ATTR_CONNECTION_STATUS); 回答2: $pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS) always return "127.0.0.1 via TCP/IP" even if i stop mysqld, to use: if ($pdo->getAttribute(PDO::ATTR_SERVER

PDO associative arrays - return associative

ぐ巨炮叔叔 提交于 2019-12-30 08:08:50
问题 I have this code: $dbInstance = DB_Instance::getDBO(); $statement = $dbInstance->prepare("SELECT id, name FROM language ORDER BY id"); $statement->execute(); $rows = $statement->fetchAll(); //Create associative array wuth id set as an index in array $languages = array(); foreach($rows as $r) { $languages[$r['id']] = $r['name']; } return $languages; I can't figure out how to use PDO-statement to achieve the same result that array $languages produces. I've tried some different fetch_styles. I