mysql

MySQL KEY question

CREATE TABLE `django_comments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `content_type_id` int(11) NOT NULL, `object_pk` longtext NOT NULL, `site_id` int(11) NOT NULL, `user_id` int(11) DEFAULT NULL, `user_name` varchar(50) NOT NULL, `user_email` varchar(75) NOT NULL, `user_url` varchar(200) NOT NULL, `comment` longtext N...

Physical/in-Memory database. (for logging purposes on my website)

We all know MYSQL. We all know memcached. I love memcached. You have a string key , and it returns a value. Dead simple. Is there a database for memory? For example, I am building a website that needs to keep track of LOGGING. Everything people do...I need to keep track of. But it would be slow to write to disk every time someone hi...

MySQL - How to select data by string length

SELECT * FROM table ORDER BY string_length(column); is there a mysql function to do this (of course instead of "string_length")? thank you! ...

HABTM Query help

I have a HABTM relationship between 'articles' and 'tags' Problem: I'm only looking for articles with BOTH the tag 'sports' and 'outdoors' but not articles with only one of these tags. I tried this: SELECT DISTINCT article.id, article.name FROM articles inner JOIN tags ON (tags.name IN ('outdoors', 'sports') inner JOIN articles_tags O...

Observed something weird with MySQL... Query suddenly becomes super fast...

I have a column "name" in a table and there are at least 10 million records. I've added an index on this name column. Now, for the first initial few searches, it was taking more than 10 seconds to return a single answer (whether the name was present or not) but suddenly, it gives me the result in less than 0.1 seconds. Am I missing somet...

Is it a good practice to write subqueries in MySQL?

I am writing the following sub query for some project specific purpose: SELECT count(*) from table1 WHERE userB='$p' AND userA IN (SELECT userB FROM table1 WHERE userA='$row[username]') I was curious if this was the best practice when doing it in PHP or should I resort to the conventional way of first getting the subquery resu...

Cannot connect to MySQL through PHP

Seems like a beginner question but I can't seem to figure it out ... I have a fresh Windows 7 x64 / Apache 2.2 / PHP 5.2 / MySQL 5 x64 installation. Actually I tried both IIS and Apache. But this PHP Code does not work: <? $hostname = "localhost"; $username = "xxx"; $password = "xxx"; $db = mysql_connect($hostname,$username,$passwo...

MySQL Query: Optimal Querying

i have this code SELECT DISTINCT idx_campus_bookinfo,c.userid as Buyer,bookname,book_explain,writedate FROM campus_bookinfo cb LEFT JOIN user_books ub ON idx_campus_bookinfo = id_product LEFT JOIN customer c ON ub.id_customer = c.id_customer where cb.idx_campus = 1 and cb.idxuser = 29 ORDER BY writedate DESC which give an output of ...

Is it really no solution to update multiple records in MySQL?

I want to do all these update in one statement. update table set ts=ts_1 where id=1 update table set ts=ts_2 where id=2 ... update table set ts=ts_n where id=n Is it? ...

PHP MYSQL - Insert into without using column names but with autoincrement field

Hi guys, I've to insert a long form with 32 fields into a mysql table. i'd like to do that something like this: $sql="insert into tblname values (... 32 fields ...)"; Obviosly it works fine if the fiedls were in the same order as the mysql table fields. But, my table has as first field an id (auto-increment). What i want to avoid i...

How to select in between?

I have a table, called Level. id | level | points(minimum) ------------------------- 1 | 1 | 0 2 | 2 | 100 3 | 3 | 200 Let say I have 189 points, how do i check which level the user in? EDIT: Best answer chosen. Now I am comparing the request by adding EXPLAIN before the SELECT query, i have this r...

How to design this "bus stations" database?

I want to design a database about bus stations. There're about 60 buses in the city, each of them contains these informations: BusID BusName Lists of stations in the way (forward and back) This database must be efficient in searching, for example, when user want to list buses which are go through A and B stations, it must run quickly...

How to update two tables in one statement?

UPDATE table1, tmpList SET table1.ts = tmpList.ts_value WHERE table1.id = tmpList.id UPDATE table2, tmpList SET table2.ts = tmpList.ts_value WHERE table2.id = tmpList.id I'm using MySQL ...

MYSQL SELECT LIKE "masks"

Hi guys, I'm using a field in a table to hold information about varios checkboxes (60). The field is parsed to a string to something like this "0,0,0,1,0,1,0,1,..." Now I want to make a search using a similar string to match the fields. I.e. "?,?,1,?,?,1,..." where the "?" means that it must be 0 or 1 (doesn't matter), but the "1...

What is second level SQL Injection

What is all about the second level SQL Injection.. This is with reference to the question http://stackoverflow.com/questions/1819377/use-of-parameters-for-mysqlquery.. and a part of one of the answers had this term... ...

MySQL syntax error

The SQL statement is mysql_query("update mytable set duration=floor(min(max(TIME_TO_SEC(TIMEDIFF(NOW(), moment))/60,5),600)) where taskid='$taskid' and memberid='$memberid'")or die(mysql_error()); and the error message is You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve...

Text data in form-field too long.

I have a form with a text area field. I put some text information there and send it as post request. This information is about 2M of text. Everything goes fine with server and database because post request sends this amount of data to server and mysql saves it correctly in DB. Problem is that after that I just can't render text data back...

MySQL Query: Query with conditional statements

i have this query SELECT IF(isnull(ub.user_lecture_id), 0, ub.user_lecture_id) as IsPurchased, cs.title,cs.start_date, cs.start_time, cs.end_time FROM campus_schedule cs LEFT JOIN campus_bookinfo cb ON cs.bookid=cb.idx_campus_bookinfo LEFT JOIN user_lectures ub ON ub.id_product = cs.idx_campus_schedule AND ub.id_customer = 11 WHER...

Is this a bad login algorithm in flash, php and mysql ?

My site is in flash. The login is also in flash. This is the login flow: Enter username and password Send to authentication.php page Here is my doubt on authentication.php page: (1) Check the post parameters, i.e username and password (2) Sha/hash the password (3) Q1(query 1), select username and password from users table (4) If ma...

Problem with MySQL full text search in combination with OR?

I have a table Document with a full text index *headline_idx* on two columns, headline and text where the text is a MEDIUMTEXT column, there is also some other fields, one of the named lang. If I do the following select: select * from Document where lang= 'en' AND match(headLine,text) against ("test") everything works OK, the fulltex...