pdo

Getting SQLSTATE[HY093]: Invalid parameter number: no parameters were bound in E:\wamp64\www\social\classes\db.php on line 12 error

為{幸葍}努か 提交于 2019-12-31 07:52:16
问题 I'm making a social network's login page but when I login a get the error above. My db.php is (i use pdo): <?php class DB { private static function connect() { $pdo = new PDO('mysql:host=127.0.0.1;dbname=social;charset=utf8', 'danny', 'password'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $pdo; } public static function query($query, $params = array()) { $statement = self::connect()->prepare($query); $statement->execute($params); if (explode(' ', $query)[0] ==

Getting SQLSTATE[HY093]: Invalid parameter number: no parameters were bound in E:\wamp64\www\social\classes\db.php on line 12 error

心已入冬 提交于 2019-12-31 07:51:46
问题 I'm making a social network's login page but when I login a get the error above. My db.php is (i use pdo): <?php class DB { private static function connect() { $pdo = new PDO('mysql:host=127.0.0.1;dbname=social;charset=utf8', 'danny', 'password'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $pdo; } public static function query($query, $params = array()) { $statement = self::connect()->prepare($query); $statement->execute($params); if (explode(' ', $query)[0] ==

PDO query returns lots of \uXXXX character codes which I can't convert to unicode characters

南楼画角 提交于 2019-12-31 07:42:31
问题 I have a MySQL database table in which I store the names of countries in different languages, and I can't get the data to display in unicode characters - I can only get \uXXXX codes displayed where the special characters should be. The query is used in an AJAX request with the results encoded as a JSON object. Here is the table (truncated): CREATE TABLE IF NOT EXISTS `tbl_countries` ( `ccode` varchar(2) character set utf8 collate utf8_unicode_ci NOT NULL default '', `country_en` varchar(100)

how to store serialized object with namespace in database using pdo php

血红的双手。 提交于 2019-12-31 07:21:48
问题 When i try to store serialized object with namespace i cant do that beacuse i got error unterminated quoted string at or near "'O:22:"protect\classes\Router". Code: $router = new protect\classes\Router(); $tmp = serialize($router); $dsn = 'pgsql:dbname=system;host=127.0.0.1'; $user = 'postgres'; $password = 'mypassword'; $pdo = new PDO($dsn, $user, $password, $options); $pdo->exec('SET search_path = temporary'); $pdo->query("SELECT replace_value('protect\classes\Router','$tmp','serialized

how to store serialized object with namespace in database using pdo php

无人久伴 提交于 2019-12-31 07:21:26
问题 When i try to store serialized object with namespace i cant do that beacuse i got error unterminated quoted string at or near "'O:22:"protect\classes\Router". Code: $router = new protect\classes\Router(); $tmp = serialize($router); $dsn = 'pgsql:dbname=system;host=127.0.0.1'; $user = 'postgres'; $password = 'mypassword'; $pdo = new PDO($dsn, $user, $password, $options); $pdo->exec('SET search_path = temporary'); $pdo->query("SELECT replace_value('protect\classes\Router','$tmp','serialized

Results of MYSQL query printed twice using PDO

梦想与她 提交于 2019-12-31 06:54:04
问题 I am a teacher and I have a mysql table called 'gabber' which holds scores of student quizzes. The fields are 'Exercise', 'realname, 'Score', 'Start_Time' and 'End_Time'. If a student completes more than one type of quiz, then this will appear as another row in the table, but of course with a different Exercise value. My code below, which very nearly works, first finds the unique exercise values, and uses these to print the table column headings. These unique exercise values are also used to

SQL: check insert successful (in a task to get 8 distinct random rows from a table with two columns)

纵然是瞬间 提交于 2019-12-31 05:59:09
问题 Update: I fixed the previous problems. Now the codes are up-dated. Results are unique and IDs are right. But new problem: The amount of result rows is often less than requirement (8). Because I added CREATE UNIQUE INDEX topicid on rands (topicid); to deny the repeated inserts in SQL layer; the loop - 1 regardless the insert is denied. I am now looking for a method like: IF insert successful THEN cnt-=1. Do you know any way to do this in SQL layer? Thanks. I have a table called topictable

PDO Database access WHERE title = $title

不羁的心 提交于 2019-12-31 05:45:09
问题 I'm trying to learn to use PDO instead of MySQLi for database access and I'm having trouble selecting data from the database. I want to use: $STH = $DBH->query('SELECT * FROM ratings WHERE title=$title ORDER BY date ASC'); $STH->setFetchMode(PDO::FETCH_ASSOC); while($row = $STH->fetch()) { echo $row['title']; } but I'm getting this error: Fatal error: Call to a member function setFetchMode() on a non-object in /home/owencont/public_html/owenstest.com/ratemystudents/index.php on line 6 If I

Cant access eximstats sqlite3 db after WHM64 upgrade

一曲冷凌霜 提交于 2019-12-31 04:57:05
问题 After WHM 64 upgradation, cant access eximstat db. MySQL code changed to PDO for accessing sqlite3 db as follows: $db = new PDO('sqlite:/var/cpanel/eximstats_db.sqlite3', DB_USER, DB_PASSWORD); The failues, defers tables are all blank. In fact, a new blank file was getting created in the var/cpanel directory, instead of getting connection to eximstats db. Surprisingly, CPanel:'View Sent summary' fetch information all correctly, But I cant access in my script which is residing on the domain.

Laravel Raw DB Insert Affected Rows

本秂侑毒 提交于 2019-12-31 04:42:17
问题 I'm using raw queries with laravel 4 , is there a way to check affected rows on an insert? DB::getPdo()->rowCount(); gives me an "undefined method" error . Code is as follows: $query = "INSERT IGNORE INTO table (id) VALUES (?)"; $doQuery = DB::insert($query, array($value)); if ($doQuery) { return DB::getPdo()->last(); } else { return 0; } If not, is there an easy way to figure out whether an insert was done or not without making it two queries? 回答1: You can use this function: int