pdo

Can I improve my PDO method (just started)

放肆的年华 提交于 2019-12-26 15:06:02
问题 I just switched to PDO from mySQLi (from mySQL) and it's so far good and easy, especially regarding prepared statements This is what I have for a select with prepared statement Main DB file (included in all pages): class DBi { public static $conn; // this I need to make the connection "global" } try { DBi::$conn = new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf8", $dbuname, $dbpass); DBi::$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); DBi::$conn->setAttribute(PDO:

Html / php not updating sql database [duplicate]

南楼画角 提交于 2019-12-26 13:33:29
问题 This question already has answers here : Html / Php form not adding to SQL database (2 answers) Closed 2 years ago . I've been working on this for hours now and including rebuilding my whole code I cannot figure out what is wrong. The HTML form is supposed to populate the patients SQL database but it is not working. I have a similar form that I am using on another part of the website that works flawlessly but this on doesn't seem to and a can't figure out why. I have checked if the $_POST 's

Fatal error: Call to undefined method CI_DB_pdo_driver::where() in

烂漫一生 提交于 2019-12-26 08:52:15
问题 I’m using PDO driver to access MySQL database. Everything is working OK on that part. My database.php looks like this: $active_group = 'default'; $active_record = FALSE; $db['default']['hostname'] = 'mysql:host=127.0.0.1:3386'; $db['default']['username'] = 'root'; $db['default']['password'] = ''; $db['default']['database'] = 'mydatabase'; $db['default']['dbdriver'] = 'pdo'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default'][

White listing effectiveness against SQL Injection

自闭症网瘾萝莉.ら 提交于 2019-12-25 19:54:14
问题 Let's say I had something like the following: function return_some_info($db, $id){ if (! preg_match("/^\d{5}$/",$id)) { header("Location: safepage.php"); exit; } $query="SELECT `column1`, `columns2` FROM `table` WHERE `columnId`=:id ORDER BY `column1` ASC"; $query_params = array( ':id' => $id ); $stmt = $db->prepare($query); $stmt->execute($query_params); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $infoArr[]=$row; }; return $infoArr; } And let's say $id is a dynamic variable that could

Possible to use a function inside of a different classes __construct?

喜欢而已 提交于 2019-12-25 19:35:53
问题 EDIT::: So I have classes that I would like to work together. My first two establish a connection to the database: dbconn.php <?php class dbconn { protected $dbname; protected $dbuser; protected $dbpassword; protected $dbhost; protected $connection; public function __construct($dbhost, $dbname, $dbuser, $dbpass) { $this->dbname = $dbname; $this->dbhost = $dbhost; $this->dbuser = $dbuser; $this->dbpass = $dbpass; $this->connect(); } public function getConnection() { return $this->connection; }

Non-Object Errors using PHP PDO with MySQL

风流意气都作罢 提交于 2019-12-25 18:55:12
问题 I've been scratching my head over this for a few days now and I've still got nowhere. I'm trying to pull a small set of values from a MySQL database via PHP PDO; I know PDO works as I am using it else where and I have based my code around te previously working code. function custom_sub_cat_list($db_details, $cat_id) { //ln21 $subcat = NULL; try { $h = new PDO("mysql:host=".$db_details['host'].";dbase=".$db_details['db'],$db_details['user'],$db_details['pass']); $h->setAttribute(PDO::ATTR

Php? PDO or mySQLi

强颜欢笑 提交于 2019-12-25 18:49:10
问题 Just writing a PHP website and using mySqli for my database connectivity. Really enjoying it as I can use Prepare statements and then do a $result = $stmt->get_result(); which loads results into an associated array. However, thought it best be time to upload a few pages and the DB to hosting site to test speed and such to find that it does not support the $stmt->get_result(); command, having it needing to use the mysqlnd driver which my host does not support. Looking into this nor does many

How to retrieve large data from mysql to php?

我只是一个虾纸丫 提交于 2019-12-25 18:45:45
问题 How can I retrieve large data from mysql to php? I've tried, but I'm getting a 1048576 characters string and my row is bigger than that. 回答1: Ok, so thanks to Pablo Jiménez, that was quick. Pdo's buffer was indeed too small, by doing so i was able to retrieve my data. $pdo = new PDO( $dsn, $username, $password, array(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => 2097152) ); 来源: https://stackoverflow.com/questions/38499063/how-to-retrieve-large-data-from-mysql-to-php

SQLSTATE[42S22]: Column not found: 1054 Unknown column '$value' in 'field list''

折月煮酒 提交于 2019-12-25 18:44:12
问题 try { $db = new PDO("mysql:host=$host;dbname=$dbname",$user,$password) ; $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $formInfo = array('fname','lname','email','password','gender') ; $entry = array() ; foreach($formInfo as $data) { $entry[$data] = $_POST[$data]; } //print_r($entry); $salt = Hash::gen_salt() ; $sqlcollum = array( 'First_name'=> $entry['fname'] , 'Last_name' => $entry['lname'] , 'email' => $entry['email'] , 'password' => Hash::gen_password($entry['password'],

Problems with charset, russian letters

南楼画角 提交于 2019-12-25 18:41:53
问题 I have a problem with charset. When im inserting values to table in russian letters it appears like this - Р?ван. This is my Database connection class. class Database { public $user = 'root'; public $password = ''; function __construct() { $this->connect(); } function connect() { try { $this->dbh = new PDO('mysql:host=localhost;dbname=university', $this->user, $this->password,array(PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES CP1251')); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE