pdo

How do I display execution time of a MySQL query in PHP?

人走茶凉 提交于 2020-01-04 03:00:48
问题 I am working on a PHP application that takes queries in a text box and returns paginated results. As part of the application I want to report the running time of the query. Here is what I have done so far. I started off by enabling profiling in by directly entering in the text box and running the script: set global profiling = 1 Using the provided text box I enter the following query: select @@profiling And get: 1 Finally, I run the query as so: select * from log However, when I run the

How to concatenate two string during MySQL UPDATE query?

ⅰ亾dé卋堺 提交于 2020-01-04 01:29:07
问题 Use case: Created a record Spot, Code, Language, Count ...later found out language entered was wrong. Tried to change the language using UPDATE query. Concatenated string still show same. Updated language string not changed in the concatenated string. Created record using this MySql query $sql = "INSERT INTO library (spot,code,language,count,litcode) values(?,?,?,?,CONCAT(language,'-',code))"; Tried to UPDATE language using this MySql query Database::connect(); $pdo->setAttribute(PDO::ATTR

Changed connection page to PDO and got mysql_error()

自古美人都是妖i 提交于 2020-01-03 19:38:13
问题 Was going over my code to turn all my queries into prepared queries (PDO). I changed my connection page accordingly. As I was cleaning up my functions page I came across the error mysql_error() expects parameter 1 to be resource, integer given which referred to my email function email_exists($email){ $query1 = mysql_query("SELECT COUNT(user_id) FROM tempusers WHERE `email` = '$email'") OR die(mysql_error(0)); $email = sanitize($email); return (mysql_result($query1,0)==1)? true : false; }

PHP (or MySQL) crash when retrieving a big database record (~5MB)

给你一囗甜甜゛ 提交于 2020-01-03 18:35:15
问题 It doesnt display any errors, just a blank page. I tried die('test') before I call my function to retrieve a record and it does it, but when I place die('test') after my retrieve row function all I get is an empty page (on chrome it says this: Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.) .. I have tried (with 128M, -1, 64M, etc) ini_set('memory_limit', -1); With no luck. I am using mysqli to retrieve the record and a simple query like

Precision loss whilst inserting a double into MySQL through PDO

做~自己de王妃 提交于 2020-01-03 16:40:26
问题 I've run into this really annoying behavior and I want to know if I'm doing something wrong, or if this is intentional (and if so, why). Whenever I have a variable in php (5.3) that is of type double and I want to insert it into the database (MYSQL 5.0) in a field that is of type double, the value always gets rounded down to 6 digits behind the point when I'm using PDO. So the below code: $stmt = $pdo->prepare("UPDATE someTable SET someDouble = :somePHPDouble;"); $number = 0.11124379542256;

PHP - MySQL PDO maximum query size

做~自己de王妃 提交于 2020-01-03 15:34:16
问题 I'm using MySQL PDO in PHP to retrieve very long string (about 1-5mb) from the database. When tested on my local machine, everything worked fine. However, on my live server, when executing a select statement, the maximum string size returned is 1048576 bytes, which is exactly 1MB. Hence, since the code is the same, this must be something in the PHP or MySQL settings. I have the follow: php.ini post_max_size = 20M my.cnf max_allowed_packet = 20M So I assume I'm not setting the correct

Using PDO to replace mysql_connect - formatting correctly?

ぃ、小莉子 提交于 2020-01-03 10:42:08
问题 This is my current page: <?php mysql_connect('localhost', 'root', 'mypass') or die (mysql_error()); mysql_select_db('radio1') or die (mysql_error()); $result = mysql_query("SELECT *, TIME_FORMAT(airtime, '%H:%i') `airtime` from presenters"); //Table starting tag and header cells while($row = mysql_fetch_array($result)) { ?> <?php foreach($rows as $row):?> <dl class="standard"> <dt><a href="<?=$row=['link'] ?>" title="<?=$row=['presenter'] ?>"><?=$row['airtime'] . " - " .$row['presenter']?></a

Value return when no rows in PDO

こ雲淡風輕ζ 提交于 2020-01-03 08:39:09
问题 I have a PDO function: function(){ $success=$this->query($query, $bindvalues); return ($success == true) ? $this->stmt->fetch(PDO::FETCH_ASSOC) : false; } When I perform a select query that returns a row (or more), it will return for example: array(1) { ["Id"]=> string(1) "1" } When the query fails (if I have a wrong syntax for example), it will return FALSE. But if no rows are found with the query it also returns FALSE. So the return value with an error in the query and with no rows will

Is the PDO Library faster than the native MySQL Functions?

≯℡__Kan透↙ 提交于 2020-01-03 07:37:32
问题 I have read several questions regarding this but I fear they may be out of date as newer versions of the PDO libraries have been released since these questions were answered. I have written a MySQL class that builds queries and escapes parameters, and then returns results based on the query. Currently this class is using the built-in mysql functions. I am well aware of the advantages of using the PDO Library, e.g. it is compatible with other databases, stored procedures are easier to execute

PHP Sql Views counter using PDO prepare()

空扰寡人 提交于 2020-01-03 06:30:28
问题 I have a variable $id wich gives me the id of the current article and this can help me to make an update query in my database on current article. This is my code: $vizualizari = $current_views+1; $sql1= "UPDATE detalii_cantari SET viz = viz WHERE id = {$id};"; $q1 = $dbh->prepare($sql1); $q1->execute(array(':viz'=>$vizualizari)); I don't get any errors but my code still not working... 回答1: Your correct code is here: $vizualizari = $current_views+1; $sql1= "UPDATE detalii_cantari SET viz =