mysql

how to optimize this query in MYSQL?

mysql> explain select a.id,a.title from users c -> straight_join iask a on c.id=a.uid -> straight_join ianswer b on a.id=b.iaskid -> -> where (c.last_check is null or b.created>c.last_check) and c.id in (1,2) -> ...

#2003 - Can't connect to MySQL server on 'localhost' (10061)

I just installed wamp.. I have mysql 5.1.33... On the icon in the task bar it says that the server is online, but when I go to open PHPMyAdmin, it gives me error 2003. Please help ...

How to select an item, the one below and the one above in MYSQL.

I have a database with ID's that are non-integers like this: b01 b02 b03 d01 d02 d03 d04 s01 s02 s03 s04 s05 etc. The letters represent the type of product, the numbers the next one in that group. I'd like to be able to select an ID, say d01, and get b05, d01, d02 back. How do I do this in MYSQL? ...

Does today's date intersect existing ranges in database PHP/MYSQL

I'm creating a time off requester for my business and I think I've run into a small issue. Goal: I want to display a page that will show me if anyone has request the current day off. Problem: I have the date_from and date_to fields which contain the information of the start and end dates for each request off. However, and I apologize...

Security risk in storing SQL login info in PHP code?

Hi everybody, First time reader, first time poster (woo!) So I've been implementing my login scripts for an informal website. Not likely to be compromised, but just to be safe, I'd like to ask if there's a security risk in having my MySQL database login stored in plaintext in the php code. As far as I know, the code itself is parsed b...

Migrating from MS SQL to MySQL: SQLOLEDB? Migration kit login error?

I've been put in charge of migrating a customer's website of MS SQL/ASP to PHP/MYSQL. I have zero experience with MS SQL. I'm trying to figure out the best way to get the current data migrated to MySQL so I can begin PHP development. Some details: I downloaded SQL Server Mangement Studio Express. I found the following string in...

Rails, MySQL and Snow Leopard

I upgraded to Snow Leopard using the disc we got at WWDC. Trying to run some of my rails apps now complains about sql (in /Users/coneybeare/Projects/Ambiance/ambiance-server) !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql. Importing all sounds in /Users...

MySQL -- joining then joining then joining again? Yuck.

MySQL setup: step by step. programs -> linked to --> speakers (by program_id) At this point, it's easy for me to query all the data: SELECT * FROM programs JOIN speakers on programs.program_id = speakers.program_id Nice and easy. The trick for me is this. My speakers table is also linked to a third table, "books." So in the "s...

MySQL enum column from anothertable column

I'm sure this is either totally impossible or really easy: If I'm creating a table and I want one of the columns to have limited options, it seems that I use either the ENUM or SET value type. But I have to define the possible values at that moment. What if I have another table which has two columns, a primary key column and a data colu...

Nhibernate 2.1 and mysql 5 - InvalidCastException on Setup

Hello there, I am trying to use NHibernate with Spring.Net und mySQL 5. However, when setting up the connection and creating the SessionFactoryObject, I get this InvalidCastException: NHibernate seems to cast MySql.Data.MySqlClient.MySqlConnection to System.Data.Common.DbConnection which causes the exception. System.InvalidCastExcept...

How should mysql be optimized/tuned for lots of writes and few reads (100:1). Read perf reqd.

I have simple db with 4 tables with a few millions rows each, and several indexes. I'm performing several hundred update and inserts on them per minute. The reads are much less frequent, but they need to be fast - for a web app. The reads should have priority - I can delay writes, if it helps improve the snappiness of reading. Curren...

Best way to organize this structure?

I have a database of foods, which I would like to divide into a tree structure of categories, subcategories and sub-subcategories. For example, fruits -> apples -> fuji, or fruits -> apples -> cortland I would like each parent page to show its immediate children (fruits page shows apples, oranges and all other fruit; apples page shows ...

Mysql substring

Hi all i'm trying to migrate to a new mail server so i want to wrote Mysql script to return a table as the following then export the result as CSV file sql statement as the following `select email,clear,email AS domain from postfix_users ` i want to substring any characters preceding the @ and the @ symbol iteself before the domai...

Parse Error for a MySQL query in PHP

I got this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/oznola38/public_html/code/classifieds.php on line 30 for this code: $qry = "INSERT INTO classified (name, address, city, state, zip, phone, fax, email, section, weeks, ad_text, link, display) VALUES ...

MySQL table incrementing by 10 for some reason

The id field in a mysql table is incrementing by 10 (11, 21, 31) for some reason. Here is the table definition: CREATE TABLE `clients` ( `id` int(11) NOT NULL auto_increment, `first_name` varchar(255) default NULL, `last_name` varchar(255) default NULL, ) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8; If I do a simple in...

Using PHP and MySQL (or other means), how should I detect an abusive visitor?

What I would like to do is implement a system that would track how many times a visitor has requested a page from my website and then based on some sort of threshold, block the visitor if I deem them abusive (i.e.: attempting a DoS). My question lies in the implementation of such a system... What would be a good way to track the activi...

Sorting modified preorder traversal mysql tree

Hey, I've implemented a tree in a mysql table using: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html This is the method where you have a table like: +-------------+----------------------+-----+-----+ | category_id | name | lft | rgt | +-------------+----------------------+-----+-----+ | 1 ...

Which one is less costly in terms of resources?

Im on an optimization crusade for one of my sites, trying to cut down as many mysql queries as I can. Im implementing partial caching, which writes .txt files for various modules of the site, and updates them on demand. I've came across one, that cannot remain static for all the users, so the .txt file thats written on the HD, will nee...

global search and replace in mysql?

I use the database of mysql by a certain system now. For data structure, there is table around 10-35 in five DB each, and there is by column around 5-40 on one table more. Well, I think whether I cannot substitute the character string that there is that there is in data of the whole these databases for a lump. Will not there be any...

PHP Function to replace symbols with character codes to stop SQL Injection

I am trying to write a php function to stop MySQL injection attempts. What I am doing is using str_replace() to remove symbols and replace them with with their HTML character code. My issue is that the codes all contain &#; but I also want to replace those symbols with their codes. How can I do this without changing the code into somet...