mysql

Querying Last Entries group by DeviceId

I have the database table logs as the following: I would like to extract the last entry of device, pollDate, status. For eg. deviceId, pollDate, status 1, 2010-95-06 10:53:28, 1 3, 2010-95-06 10:26:28, 1 I tried to run the following query but the distinct only selects the f...

PHP:How can I send the Data entered by a user in a text field to a txt file?

In PHP How can I send the Data entered by a user in a text field to a txt file inside of a folder on my server. ...

PHP - error when insert date into MySQL

Hello everyone: I've got a typical problem when trying to insert a date into MySQL. The column defined in MySQL is of type DATE. My PHP version is 5.3.0 Apart from this date-related issue, the rest of my code works just fine. And this is my PHP script to do this: $tablename = BOOKS_TABLE; $insert = mysql_query("INSERT INTO $tabl...

Speed-up of readonly MyISAM table

We have a large MyISAM table that is used to archive old data. This archiving is performed every month, and except from these occasions data is never written to the table. Is there anyway to "tell" MySQL that this table is read-only, so that MySQL might optimize the performance of reads from this table? I've looked at the MEMORY storage ...

Get user IP via comment Form

I have inserted a hidden input in my comment form: $ip = $_SERVER['REMOTE_ADDR']; <input type="hidden" name="c-ip" value="<?php echo $ip; ?>"> Query : $cname = removeXSS(mysql_real_escape_string($_post['c-name'])); . . . $sql = "INSERT INTO guestbook (id, date, name, email, comment, ip, status) VALUES (' ', NOW(), '$cname', '$cemail'...

mysql function warning

hi here is a short version of function which im using on daily basis, it works fine except it throws a warning 'No data - zero rows fetched, selected, or processed (errno. 1329)'. and since i start using this function with django there cant be any warning or error because it stop the whole process i have read that there is no warning fi...

Scalable Full Text Search With Per User Result Ordering

What options exist for creating a scalable, full text search with results that need to be sorted on a per user basis? This is for PHP/MySQL (Symfony/Doctrine as well, if relevant). In our case, we have a database of workouts that have been performed by users. The workouts that the user has done before should appear at the top of the res...

Query with multiple IN-statements but without the cartesian product

How could I make this kind of query e.g. in MySQL SELECT * FROM Table t WHERE t.a IN (1,2,3) AND t.b IN (4,5,6) AND t.c IN (7,8,9) ... so that the result would contain only the three rows: t.a|t.b|t.c ---+---+--- 1 | 4 | 7 2 | 5 | 8 3 | 6 | 9 The above query of course returns all the combinations of the values in the IN claus...

rookie MySql question about paging; Is one query enough?

I have managed to get paging to work, almost. I want to display to the user, total nr of records found, and the currently displayed records. Ex: 4000 found, displaying 0-100. I am testing this with the nr 2 (because I don't have that many records, have like 20). So I am using LIMIT $start, $nr_results; Do I have to make two queries i...

mysql_fetch_object on complex objects

Say for example I have the follwoing DB structure Table book id title ... Table Author id name ... Table BookAuthor id bookid authorid And in PHP I have the following object class Book { var $id; var $title; var $authors = array(); function Book() {} } class Author { var $id; var $name; function Author(){} ...

rake db:migrate fails when trying to do inserts

I'm trying to get a database populate so I can begin working on a project. This project is already built and I'm being brought in to help with front-end work. Problem is I can't get rake db:migrate to do any inserts. Every time I run rake db:migrate I get this: == 20081220084043 CreateTimeDimension: migrating ========================...

From comma separated list to individual item result set. *mysql

I'm doing some data migration from a horribly designed database to a less horribly designed database. There is a many to many relationship that has a primary key in one table that corresponds to a comma separated list in another. FK_ID | data ------------- 1,2 | foo 3 | bar 1,3,2 | blarg Is there a way to output the FK_ID field ...

Another rookie question; How to implement Count() here?

I have this query: SELECT mt.*, fordon.*, boende.*, elektronik.*, business.*, hem_inredning.*, hobby.* FROM classified mt LEFT JOIN fordon ON fordon.classified_id = mt.classified_id LEFT JOIN boende ON boende.classified_id = mt.classified_id LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id LEFT JOIN business ON bu...

Storing strings in MySQL

I've got a C# application which takes a users notes which can include various punctuation marks such as commas, apostrophes, semicolons etc. At the moment I'm getting my application to encode the strings and storing them into the database as base 64. Is there a better way? FYI: I'm using a MySQL through their ODBC driver ...

Optimize master-detail insert statements

Quest After a day of running (against nearly 1 GB of data), a set of statements are tumbling down to 40 inserts per second. I am looking to increase that by an order of magnitude or two. SQL Code The code to insert the information comes in two parts: a master record and detail records. The master record: INSERT INTO MONTH_REF (DISTRI...

Log Mysql warnings

I'm trying to get Mysql to log all warnings to the log file. I'm running stored procedures, and I want to get at the warnings they generate. ...

Haskell Target Architecture

I am trying to use the HDBC MySQL driver in my project. I seem to be having a problem related to target architecture of the processor. ld: warning: in /usr/local/mysql/lib/libmysqlclient.dylib, file was built for unsupported file format which is not the architecture being linked (i386) Since it can't read the file all the external refe...

Intermittent "No Database Selected" in PHP/MySQL?

Have a PHP/MySQL form with a dropdown box containing a list of 350 names. When any random name is selected, sometimes it works & displays info about that name from the database, and sometimes the form gives the error "No Database Selected". Here's what I've tried, pretty much grasping at straws as I'm not a programmer: Increasing max...

Retrieving data with a hierarchical structure in MySQL

Given the following table id parentID name image 0 0 default.jpg 1 0 Jason 2 1 Beth b.jpg 3 0 Layla l.jpg 4 2 Hal 5 4 Ben I am wanting to do the following: If I search for Ben, I would like to find the image, if t...

I need to convert my Mysql database to SQL Server 2005 database

I need to convert my Mysql database to SQL Server 2005 database, Is there any tools available for this conversion. ...