pdo

Reconnecting on MySQL Server Has Gone Away

对着背影说爱祢 提交于 2021-02-02 08:53:12
问题 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 )

Reconnecting on MySQL Server Has Gone Away

送分小仙女□ 提交于 2021-02-02 08:53:01
问题 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 )

Data type differences between PHP sqlsrv driver and PDO driver

我的梦境 提交于 2021-02-02 02:23:53
问题 Here I am using sqlsrv : $conn = sqlsrv_connect("192.168.1.102,1433", array("Database"=>"RF_User", "UID"=>"rfo-gcp", "PWD" => "")); $tsql = "SELECT birthdate FROM tbl_rfaccount WHERE id = ?"; $stmt = sqlsrv_query($conn, $tsql, array("test")); $result = sqlsrv_fetch_array($stmt); var_dump($result); Result: array(2) { [0]=> object(DateTime)#1 (3) { ["date"]=> string(26) "2020-04-19 20:40:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } ["birthdate"]=> object(DateTime)#1 (3

Data type differences between PHP sqlsrv driver and PDO driver

风格不统一 提交于 2021-02-02 02:22:20
问题 Here I am using sqlsrv : $conn = sqlsrv_connect("192.168.1.102,1433", array("Database"=>"RF_User", "UID"=>"rfo-gcp", "PWD" => "")); $tsql = "SELECT birthdate FROM tbl_rfaccount WHERE id = ?"; $stmt = sqlsrv_query($conn, $tsql, array("test")); $result = sqlsrv_fetch_array($stmt); var_dump($result); Result: array(2) { [0]=> object(DateTime)#1 (3) { ["date"]=> string(26) "2020-04-19 20:40:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } ["birthdate"]=> object(DateTime)#1 (3

Data type differences between PHP sqlsrv driver and PDO driver

牧云@^-^@ 提交于 2021-02-02 02:18:23
问题 Here I am using sqlsrv : $conn = sqlsrv_connect("192.168.1.102,1433", array("Database"=>"RF_User", "UID"=>"rfo-gcp", "PWD" => "")); $tsql = "SELECT birthdate FROM tbl_rfaccount WHERE id = ?"; $stmt = sqlsrv_query($conn, $tsql, array("test")); $result = sqlsrv_fetch_array($stmt); var_dump($result); Result: array(2) { [0]=> object(DateTime)#1 (3) { ["date"]=> string(26) "2020-04-19 20:40:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } ["birthdate"]=> object(DateTime)#1 (3

PHP PDO how to run a multiple query request?

半腔热情 提交于 2021-02-01 05:04:22
问题 Hello I'm trying to execute this SQL request in PHP with PDOStatement : CREATE TEMPORARY TABLE r1 SELECT CONCAT(MONTH(Heure_deb),'/',DAY(Heure_deb)) as 'Date', Heure_deb, Operateur.Id_op , Nom_op , Prenom_op, Nom_act , TIME(Heure_deb) as heure, Commentaire, Type FROM Operateur, Pointage, Activite WHERE Operateur.Id_op = Pointage.Id_op AND Activite.Id_act = Pointage.Id_act ORDER BY date, Id_op, heure ; Create temporary table r2 SELECT a.Id_op, a.Heure_deb, MIN(b.heure_deb) as fin, TIMEDIFF(b

PHP PDO how to run a multiple query request?

烈酒焚心 提交于 2021-02-01 05:03:46
问题 Hello I'm trying to execute this SQL request in PHP with PDOStatement : CREATE TEMPORARY TABLE r1 SELECT CONCAT(MONTH(Heure_deb),'/',DAY(Heure_deb)) as 'Date', Heure_deb, Operateur.Id_op , Nom_op , Prenom_op, Nom_act , TIME(Heure_deb) as heure, Commentaire, Type FROM Operateur, Pointage, Activite WHERE Operateur.Id_op = Pointage.Id_op AND Activite.Id_act = Pointage.Id_act ORDER BY date, Id_op, heure ; Create temporary table r2 SELECT a.Id_op, a.Heure_deb, MIN(b.heure_deb) as fin, TIMEDIFF(b

PHP PDO how to run a multiple query request?

。_饼干妹妹 提交于 2021-02-01 05:03:06
问题 Hello I'm trying to execute this SQL request in PHP with PDOStatement : CREATE TEMPORARY TABLE r1 SELECT CONCAT(MONTH(Heure_deb),'/',DAY(Heure_deb)) as 'Date', Heure_deb, Operateur.Id_op , Nom_op , Prenom_op, Nom_act , TIME(Heure_deb) as heure, Commentaire, Type FROM Operateur, Pointage, Activite WHERE Operateur.Id_op = Pointage.Id_op AND Activite.Id_act = Pointage.Id_act ORDER BY date, Id_op, heure ; Create temporary table r2 SELECT a.Id_op, a.Heure_deb, MIN(b.heure_deb) as fin, TIMEDIFF(b

How to inject multiple PDO instances in Slim 4

﹥>﹥吖頭↗ 提交于 2021-01-29 14:10:39
问题 I've just started using Slim 4 (also brand new to Slim as a whole) and after reading up and following some articles I've managed to get a skeleton app setup with a PDO connection to the DB. I'm now looking to inject a second PDO instance so that a second database can be used based on the request, though I'm struggling to get my head around how to do this. My current setup is: settings.php $settings['db'] = [ 'driver' => 'mysql', 'host' => 'database', 'username' => 'root', 'database' => 'demo'

Binding values within a function to INSERT INTO DB

杀马特。学长 韩版系。学妹 提交于 2021-01-29 04:25:43
问题 Lets say I have this code: $array = array('one' => $one, 'two' => $two); $sql->sql_insert('table_name', $array); I have the class object $sql and the function sql_insert but how would I use the mysqli prepared statements to bind the values and insert it into the db? And lets say the mysqli connection is $this->connection Any advice would be great thanks. edited: function sql_insert_bind($table, $insert){ $count = count($insert); $bind_val = ''; for($i = 0; $i <= $count; $i++){ $bind_val .= '?