pdo

MySQL connection over SSL with Laravel

我与影子孤独终老i 提交于 2020-06-25 02:16:11
问题 I have a problem connecting to my database over ssl in a Laravel application. My config is as follows: 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, 'sslmode' =

MySQL connection over SSL with Laravel

别来无恙 提交于 2020-06-25 02:16:08
问题 I have a problem connecting to my database over ssl in a Laravel application. My config is as follows: 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, 'sslmode' =

Trying to access array offset on value of type bool

。_饼干妹妹 提交于 2020-06-22 13:10:07
问题 $query = $pdo -> prepare("SELECT * FROM Users WHERE Username =:Username"); $query->bindParam(':Username', $name); $query->execute(); $nameRes = $query->fetch(PDO::FETCH_ASSOC); if ($nameRes['Username']==$_POST['username']) { die ("Username is already in use!"); } $query = $pdo -> prepare("SELECT * FROM Users WHERE Email =:Email"); $query->bindParam(':Email', $email); $query ->execute(); $emailRes = $query->fetch(PDO::FETCH_ASSOC); if ($emailRes['Email']==$_POST['email']) { die ("Email is

Call to a member function on null?

倖福魔咒の 提交于 2020-06-10 16:10:22
问题 I have done all sorts of things to understand what is actually wrong with the code, but I just couldn't figure out what was causing this error. Below is class called Topic : class Topic { // Init DB variables private $db; /* * Constructor */ public function __contruct() { $this->db = new Database(); } /* * Get All Topics */ public function getAllTopics() { $this->db->query("SELECT topics.*, users.username, users.avatar, categories.name FROM topics INNER JOIN users ON topics.user_id = users.id

inserting data error code 23000 mysql pdo php

南楼画角 提交于 2020-06-09 04:29:08
问题 i have a table in my databse i am trying to insert some data inside it but i keep getting pdo error code 23000 i tried the query manually and it worked so the proplem isn't with the query my code : <? include ('config.php'); $text=$_POST['text']; if (!isset ($text)) exit(); $query=$db->prepare("INSERT INTO posts (post,userid,votes) VALUES (?,?,0)"); $query->bindValue(1,$text,PDO::PARAM_STR); $query->bindValue(2,$id,PDO::PARAM_INT); $re=$query->execute(); if ($re) echo 'Added'; else die($query

PHP passing string with apostrophe to shell_exec

穿精又带淫゛_ 提交于 2020-06-08 19:59:18
问题 I’m trying to pass a string (drawn from a PDO query to an MYSQL DB) via PHP shell_exec to a *nix program, in this case xtide. All works fine until I pass a string containing an apostrophe. This works in the Terminal on OSX: house@New-MacBook-Pro:~$ tide -l "Nomans Land, Martha's Vineyard, Massachusetts" but the exact same string, from a PDO query to a MYSQL DB, and passed as a variable into shell_exec, always fails. It doesn’t seem to matter how I arrange the single/double quotes. Running

how SELECT people within age range [duplicate]

▼魔方 西西 提交于 2020-06-08 06:10:48
问题 This question already has answers here : Mysql: Select all data between two dates (7 answers) SQL Select query that returns a range [duplicate] (4 answers) Closed 6 years ago . I've already tried all other questions/solutions, and no answer. so here it is: I need to SELECT * FROM people WHERE (dob is 18 to 40) but my dob is stored as DATE type YYYY-MM-DD need to select people between 18 and 40 for example! 回答1: You need to use BETWEEN with some year calculation TIMESTAMPDIFF(YEAR,'1980-02-04'

Autocommit with PDO

£可爱£侵袭症+ 提交于 2020-05-31 04:05:21
问题 The rollback of my transaction doesn't work. How do I set autocommit to false (or 0) in the php script using PDO (I have InnoDB 5.7.18) ? Here is my code: global $bdd; //defined with PDO try { $bdd->beginTransaction(); /* my requests */ $bdd->commit(); } catch (Exception $e) { $bdd->rollBack(); return $e->getMessage(); } return true; } 回答1: $db = new PDO('mysql:dbname=employee'); $db->setAttribute(PDO::ATTR_AUTOCOMMIT,0); var_dump($db->query('SELECT @@autocommit')->fetchAll()); 回答2: I solved

Autocommit with PDO

旧巷老猫 提交于 2020-05-31 04:03:00
问题 The rollback of my transaction doesn't work. How do I set autocommit to false (or 0) in the php script using PDO (I have InnoDB 5.7.18) ? Here is my code: global $bdd; //defined with PDO try { $bdd->beginTransaction(); /* my requests */ $bdd->commit(); } catch (Exception $e) { $bdd->rollBack(); return $e->getMessage(); } return true; } 回答1: $db = new PDO('mysql:dbname=employee'); $db->setAttribute(PDO::ATTR_AUTOCOMMIT,0); var_dump($db->query('SELECT @@autocommit')->fetchAll()); 回答2: I solved

How to check in PHP if more PDO parameters provided than needed

北城以北 提交于 2020-05-29 10:20:06
问题 I have following piece of code (PHP 7.3.16) which retrieves some data from database (MySQL): // db credentials $dbhost = "localhost"; $dbuser = "user"; $dbpass = "password"; $dbname = "database"; // pdo $dsn = "mysql:host=".$dbhost.";dbname=".$dbname.";charset=utf8"; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false ]; $pdo = new PDO($dsn, $dbuser, $dbpass, $options); // run sql query $sql = "SELECT