pdo

Sql queries binding variables vs specifying them

怎甘沉沦 提交于 2019-12-30 07:45:10
问题 I am creating a simple query in mySql to insert some values from a form into my db. My question is simple, but in reference to the difference between binding variables vs specifying them into the sql statement. Binding: $query = "INSERT INTO test (name, lastName, price) VALUES (:name, :lastName, :price)"; $apply = $con -> prepare($query); $apply -> execute (array(':name'=>$name,':lastName'=>$lastName,':price=>$price')); Typical: $query = "INSERT INTO test (name, lastName, price) VALUES ($name

PDO Multi-query “SQLSTATE[HY000]: General error”

 ̄綄美尐妖づ 提交于 2019-12-30 07:42:48
问题 I'm still learning PDO so I might of missed something but basically I'm trying to insert a row into a table and then select the generated id. I'm not sure if it likes both queries in one pdo statement. Here is the code I'm using to execute the SQL. public function ExecuteQuery($sql, $params = array()) { if($this->_handle == null) $this->Connect(); $query = $this->_handle->prepare($sql); foreach($params as $key => $value) { if(is_int($value)){ $query->bindValue(':'.$key, $value, \PDO::PARAM

Illegal String Offset within PDO For Each loop

浪尽此生 提交于 2019-12-30 04:53:09
问题 PHP Query: <?php $query = $db->prepare('SELECT * FROM Locations WHERE user_id = :id LIMIT 0, 5'); $query->bindParam(":id",$id); $result = $query->execute(); $rows = $query->fetch(); foreach ($rows as $row) { echo $row["timestamp"]; "<br />"; } ?> The two rows that should be printed (timestamp): What actually prints: 1188((22 The error within the console: PHP Warning: Illegal string offset 'timestamp' in /Sites/pages/user_account.php on line 73 - Line 73 being the echo $row... inside the

Using the Haversine formula with PostgreSQL and PDO

▼魔方 西西 提交于 2019-12-30 03:29:09
问题 On my site I'm trying to get locations nearby. I'm trying to use the Haversine formula for this. http://en.wikipedia.org/wiki/Haversine_formula MySQL Great Circle Distance (Haversine formula) Calculate zipcodes in range I'm using the following query to get all the locations within a 25km radius. SELECT id, ( 6371 * acos( cos( radians(51.8391) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(4.6265) ) + sin( radians(51.8391) ) * sin( radians( lat ) ) ) ) AS distance FROM shops HAVING

PDO bind_param is undefined method [duplicate]

烂漫一生 提交于 2019-12-29 09:07:29
问题 This question already has answers here : Can I mix MySQL APIs in PHP? (4 answers) Closed last year . I'm moving away from mysql and mysqli as many users on stackoverflow are constantly saying good things about it. I've made a database class and have tested this, this connects fine to the database. I've tried to update my prepared statements to match however I am in unfamiliar territory and have ended up getting the following error: Fatal error: Call to undefined method PDOStatement::bind

PDO bind_param is undefined method [duplicate]

佐手、 提交于 2019-12-29 09:06:32
问题 This question already has answers here : Can I mix MySQL APIs in PHP? (4 answers) Closed last year . I'm moving away from mysql and mysqli as many users on stackoverflow are constantly saying good things about it. I've made a database class and have tested this, this connects fine to the database. I've tried to update my prepared statements to match however I am in unfamiliar territory and have ended up getting the following error: Fatal error: Call to undefined method PDOStatement::bind

PDO and nested fetching

前提是你 提交于 2019-12-29 08:25:52
问题 Let's say I have something like this: $db=new PDO($dsn); $statement=$db->query('Select * from foo'); while ($result=$statement->fetch()) { //do something with $result } How would I put another query inside of that while loop? Even if I make a new PDOStatement object, it seems that that overwrites the cursor for the topmost PDO statement. The only other solution I see is to either a) fetch the entire outer loop at once or b) open 2 different connections to the database. Neither of these seem

What is the difference between the nd_pdo_mysql and pdo_mysql extensions?

人走茶凉 提交于 2019-12-29 07:51:54
问题 For some reason the pdo_mysql PHP extension, on our hosted server, fails to run a query that uses a MySQL view, with this error message. SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (There is a discussion on Bug #42041 Prepared-Statement fails when MySQL-Server under load, as well as numerous questions on Stack Overflow.) For some reason, the query using the view runs just fine, if we switch to using the nd_pdo_mysql extension, which is for the MySQL Native

PHP PDO exception: could not find driver

人盡茶涼 提交于 2019-12-29 07:43:53
问题 Does the MySQL-server and PHP5-MySQLi version have to match in order for a connection to be possible? I'm currently receiving the error below: I am running BSD. "Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'..." Here is the the connection info: $info = "mysql:dbname=myDB;host=localhost"; $user = "dbUser"; $pw = "somePW"; return(new PDO($info, $user, $pw)); Here is my MySQL information: mysql-server-5.5.24 php5-mysqli-5.4.3 回答1: PDO uses database specific

PHP PDO bindParam with html content

拈花ヽ惹草 提交于 2019-12-29 07:18:31
问题 I try to save html content to the database, with ' or " it auto give a slash which is great so I don't have to do mysql_escape_string. However when I load up the string it shows as <a href=/"yes/">test</a> and if I save it again I got this <a href=//"yes//">test</a> Does that means when I echo out the string I should strip out the slash? $html = '<a href="yes">test</a>'; $insertStatement = $pdo->prepare('insert into content (html) values (:html)'); $pdo->bindParam(:html, $html); $pdo->execute