mysql

Code for 'any' variable?

I want to consolidate the following code. Although I'm not sure how to reference SELECT * FROM any table ending in listing. $this->displaylistings=mysql_query("SELECT * FROM nordstromlisting WHERE ShopperID = '$this->ShopperID' UNION ALL SELECT * FROM saksfifthavenuelisting WHERE ShopperID = '$this->ShopperID' UNION ALL SELECT * ...

Complex rails query - unions? sub-select? can I still used named_scope?

Part of why I love Rails is that I hate SQL - I think it's more like an assembly language that should be manipulated with higher level tools such as ActiveRecord. I seem to have hit the limits of this approach, however, and I'm out of my depth with the SQL. I have a complex model with lots of sub-records. I also have a set 30-40 named...

Why does ActiveRecord generated SQL includes Date for a Time column?

When I create a SQL Time column I get a pure time, ie. no date. But when I use the Ruby Time class I get a date as well. The problem is when do a 'find' the generated SQL includes a date and I seem to be getting weird results. The Table start_date: time end_time: time day_of_week: string ActiveRecord def self.now_playing self.fi...

How to optimize MySQL Views

I have some querys using views, and these run a lot slower than I would expect them to given all relevant tables are indexed (and not that large anyway). I hope I can explain this: My main Query looks like this (grossly simplified) select [stuff] from orders as ord left join calc_order_status as ors on (ors.order_id = ord.id) calc_...

Database design for school attendance system

I'm working on a project for a school where a particular module deals with attendance system. I'm using LAMP(PHP 5.2+ MYSQL 5+) stack for development. Now the school strength is around 1500 and total number of working days per year is around 250. Plus, I've to keep records for 5 years before it can be erased. The table structure is st...

Odd class problem

In the midst of making my code OO, and ran upon this problem. The following class is giving me a weird problem. when I created the function CartTotal(), it echo'd out the proper values, BUT function DisplayListings(); did not display any MySQL data (both use $this->displaylistings). And if I change the order on my page in which I call th...

What is the best Linux filesystem for MySQL (InnoDB)?

I tried to look for benchmark on the performances of various filesystems with MySQL InnoDB but couldn't find any. My database workload is the typical web-based OLTP, about 90% read, 10% write. Random IO. Among popular filesystems such as ext3, ext4, xfs, jfs, Reiserfs, Reiser4, etc. which one do you think is the best for MySQL? ...

How can I make an average of dates in MySQL?

How can I make an average between dates in MySQL? I am more interested in the time values, hours and minutes. On a table with: | date_one | datetime | | date_two | datetime | Doing a query like: SELECT AVG(date_one-date_two) FROM some_table WHERE some-restriction-applies; Edit: The AVG(date1-date2) works but I have no clu...

Unable to rescue from "Lost connection to MySQL server" error

I have a block like so: begin # some SQL request rescue Mysql::Error => e logputs "Mysql::Error occurred, retrying in 10s: #{e.message}" sleep 10 retry end But when a "Lost connection to MySQL server" error occurred, this block was not able to catch it and retry (the MySQL server was restarted). Any idea how I ...

How to properly implement a custom session persister in PHP + MySQL?

I'm trying to implement a custom session persister in PHP + MySQL. Most of the stuff is trivial - create your DB table, make your read/write functions, call session_set_save_hander(), etc. There are even several tutorials out there that offer sample implementations for you. But somehow all these tutorials have conveniently overlooked one...

What factors should determine how often a table is optimized in MySQL?

I've seen many different schedules for optimizing tables in MySQL: everything from immediately after a delete, to once a day, to never. I have often setup a cron job to run every night to optimize all the tables. What factors do you use to determine how often a table should be optimized? ...

Is there an effect on the speed of a query when using SQL_CALC_FOUND_ROWS in MySQL?

The other day I found the FOUND_ROWS() (here) function in MySQL and it's corresponding SQL_CALC_FOUND_ROWS option. The later looks especially useful (instead of running a second query to get the row count). I'm wondering what speed impact there is by adding SQL_CALC_FOUND_ROWS to a query? I'm guessing it will be much faster than runnni...

mysql search over two tables with some kind of inner join

table estate_common -> common data for estate as title name etc. estate could differ in kind for example kind 1 - flat kind 2 - house etc. id | kind | title | name 596 | 1 | title 596 | name 596 597 | 1 | title 597 | some 597 598 | 1 | title 598 | some 598 599 | 1 | title 599 | some 599 600 | 1 | title 600 | some 600...

MySQL/Ruby on Windows

I am trying to use Rails 2.3.2 with MySQL 5.0 on Windows XP with no luck. I have installed MySQL and am able to run it, add tables etc. In ruby, the require 'mysql' statement passes but onde it reached the first action then I get > C:/Development/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql...

Working with Master / Detail SQL Data in PHP

I'm a newbie so bear with me. I'm making a little forum for fun. Check it: Categories: `id` int(10) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `position` int(11) NOT NULL, PRIMARY KEY (`id`) Forums: `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` text NOT NULL, `position...

MySql in WinXP and Mac OS X

Hello Folks, I am facing this bizarre problem. I am coding on my machine in Win XP and then moving all the code to Mac OS X machine. Running it using the jars from XP machine. I am coding in java and using hibernate for database processing. Somehow I am not able to insert one row, while the keys are generated using the increment ge...

Mysql Errors

I recently bought a ptc script and I am getting the following errors on my site alphabux.com: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/alphabux/public_html/sitestats.php on line 4 Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/...

MySQL - Selecting a Column not in Group By

I'm trying to add features to a preexisting application and I came across a MySQL view something like this: SELECT AVG(table_name.col1), AVG(table_name.col2), AVG(table_name.col3), table_name.personID, table_name.col4 FROM table_name GROUP BY table_name.personID; OK so there's a few aggregate functions. You c...

working with django and sqlalchemy but backend mysql

i am working with python django framework but in model part is sqlalchemy and back end data base is mysql how i will configure them??? ...

Does MySQL's LIMIT keyword guarantee order of returned data?

I am new to MySQL, but I have used Oracle for some time. I am a little confused about MySQL's LIMIT keyword. Does this keyword imply that the order of the returned data will be the same every time the query is executed? What if more data is added to the tables that affect the query? And how would the data be ordered if no order-by clause...