pdo

Insert BIT value in MySQL using PDO Prepared Statement

ε祈祈猫儿з 提交于 2021-02-05 04:54:59
问题 How do I insert a BIT value in MySQL using a PDO Prepared Statement? Below is what I tried and my results. <?php function testIt($value) { $sql='INSERT INTO test(id,data) VALUES(?,?)'; $stmt=db::db()->prepare($sql); $stmt->execute(array(0,$value)); $id=db::db()->lastInsertId(); $sql='SELECT * FROM test WHERE id='.$id; $stmt=db::db()->query($sql); $rs=$stmt->fetch(PDO::FETCH_ASSOC); echo("Test for {$value} returns id {$rs['id']} and data {$rs['data']}<br>"); } date_default_timezone_set(

Fatal error: Call to undefined method PDOStatement::lastInsertId()

被刻印的时光 ゝ 提交于 2021-02-04 21:16:06
问题 I have created a database class for PDO connection. Inserted record and tried to get last insert id after that getting this error "Fatal error: Call to undefined method PDOStatement::lastInsertId()". Database class: class Database { public static $link = null ; public static function getLink( ) { if ( self :: $link ) { return self :: $link ; } $ini = "config.ini" ; $parse = parse_ini_file ( $ini , true ) ; $driver = $parse [ "db_driver" ] ; $dsn = "${driver}:" ; $user = $parse [ "db_user" ] ;

Fatal error: Call to undefined method PDOStatement::lastInsertId()

天涯浪子 提交于 2021-02-04 21:15:09
问题 I have created a database class for PDO connection. Inserted record and tried to get last insert id after that getting this error "Fatal error: Call to undefined method PDOStatement::lastInsertId()". Database class: class Database { public static $link = null ; public static function getLink( ) { if ( self :: $link ) { return self :: $link ; } $ini = "config.ini" ; $parse = parse_ini_file ( $ini , true ) ; $driver = $parse [ "db_driver" ] ; $dsn = "${driver}:" ; $user = $parse [ "db_user" ] ;

PHP Mysql PDO: General error: 2006 MySQL server has gone away

感情迁移 提交于 2021-02-04 21:10:31
问题 Im currently running a custom php script which when running on my localhost works fine however when running on shared hosting, i receive the following error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away' in ...... 205 Stack trace: 0 ........ PDO->prepare('SELECT * FROM o...') #1 {main} thrown in .......... on line 205 (I've replaced the file paths with .......) Things I have tried: Adding PDO::ATTR_TIMEOUT =>

PHP PDO bindParam() and MySQL BIT

一世执手 提交于 2021-02-04 20:51:32
问题 I'm trying to update data in a table with a BIT type value in it, like the following : // $show_contact is either '1' or '0' $query->bindValue(':scontact', $show_contact, PDO::PARAM_INT); The problem is, it never changes the value, it remains '1' as set on PHPMyAdmin. I tried different PDO::PARAM_ types without success, everything else is working. edit full script $sql = "UPDATE users SET password = :password, address = :address, postal = :postal, city = :city, contact = :contact, show

PHP PDO bindParam() and MySQL BIT

谁说胖子不能爱 提交于 2021-02-04 20:51:06
问题 I'm trying to update data in a table with a BIT type value in it, like the following : // $show_contact is either '1' or '0' $query->bindValue(':scontact', $show_contact, PDO::PARAM_INT); The problem is, it never changes the value, it remains '1' as set on PHPMyAdmin. I tried different PDO::PARAM_ types without success, everything else is working. edit full script $sql = "UPDATE users SET password = :password, address = :address, postal = :postal, city = :city, contact = :contact, show

How to multiple query results in order to reduce the query number?

六眼飞鱼酱① 提交于 2021-02-04 11:36:08
问题 I want to list comments from my database depending on their type. There are three types of comments in my database and I call them with three different queries. //01 - Awaiting Comments $query = $handler->prepare("SELECT * FROM comments WHERE confirmed = 0"); $query->execute(); $r = $query->fetchAll(PDO::FETCH_ASSOC); echo "<h1>Awaiting Comments</h1>"; foreach($r as $r_) { echo "<li>r_[title]</li>"; } //02 - Comments waiting for confirmation $query = $handler->prepare("SELECT * FROM comments

PHP PDO Prepared statement bind NULL value

眉间皱痕 提交于 2021-02-04 06:18:05
问题 I'm trying to run a SQL query as a prepared statement - and I try to bind a NULL value. Well I've done some research on the web and yes, I already found all the known topics here on stackoverflow. My code so far: $stmt = $db->prepare("SELECT c.*, COUNT(d.servername) as servercount, d.controller FROM customers C JOIN customerdata d ON c.id = d.customer WHERE isVdi = :isVdi AND d.controller = :controller GROUP BY d.customer ORDER BY c.name ASC, c.environment ASC"); $stmt->bindValue(':isVdi',

PHP PDO Prepared statement bind NULL value

余生长醉 提交于 2021-02-04 06:17:25
问题 I'm trying to run a SQL query as a prepared statement - and I try to bind a NULL value. Well I've done some research on the web and yes, I already found all the known topics here on stackoverflow. My code so far: $stmt = $db->prepare("SELECT c.*, COUNT(d.servername) as servercount, d.controller FROM customers C JOIN customerdata d ON c.id = d.customer WHERE isVdi = :isVdi AND d.controller = :controller GROUP BY d.customer ORDER BY c.name ASC, c.environment ASC"); $stmt->bindValue(':isVdi',

Reconnecting on MySQL Server Has Gone Away

孤人 提交于 2021-02-02 08:57:32
问题 How can I modify this class to catch exception where MySQL Server Goes Away, and reconnect? <?php class DBConn { private $conn; public function __construct( $persistent = false ) { try { $this->conn = new PDO( "mysql:host=localhost;dbname=test", 'test', "hoollaahaoo" ); $this->conn->exec( "SET CHARACTER SET utf8" ); $this->conn->setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC ); if ( $persistent ) $this->conn->setAttribute( PDO::ATTR_PERSISTENT, true ); } catch( PDOException $e )