mysql

How important is it to select the smallest possible data type when designing a database?

How much of a difference does using tinyint or smallint (when applicable) instead of just int do? Or restricting a char field to the minimum characters needed? Do these choices affect performance or just allocated space? ...

Tomcat6 can't connect to MySql (The driver has not received any packets from the server)

Hi all, i'm running an Apache Tomcat 6.0.20 / MySQL 5.1.37-lubuntu / sun-java6-jdk /sun-java6-jre / sun-java6-bin on my local machine using Ubuntu 9.10 as OS. I'm trying to get a simple DB-query example running for 2 days now, but i still get this Exception: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.serv...

Notice: Undefined index

I have a checkbox which can make a post password protected- <p><strong><label for="password">Password protect?</label></strong> <input type="checkbox" name="password" id="password" value="1" /></p> My Php tries to post- $password = htmlspecialchars(strip_tags($_POST['password'])); I get the undefined index error. Now, if I try to...

How do I calculate and use a Morton (z-index) value to index geodata with PHP/MySQL?

I have a MySQL table of records, each with a lat/lng coordinate. Searches are conducted on this data based on a center point and a radius (any records within the radius is returned). I'm using the spherical law of cosines to calculate the distance within my query. My problem is that indexing the geodata is horribly inefficient (lat/lng v...

Filtering XML results using jquery

Using jquery is it possible to filter XML results that are loaded? Ideally i would like to do a mysql style filer/search like SELECT * FROM "example_table" WHERE id="1" I have an XML file loaded in to my application with the following structure <country> <state id="1"> <statename>Baden-Wurttemberg</statename> <cities> ...

Recovery after wrong MySQL update query?

I made a wrong update query in my table. I forgot to make an id field in the WHERE clause. So that updated all my rows. How to recover that? I didn't have a backup.... ...

MySQL row subquery (multiple columns) with CASE (not in where-clause)

I want to retrieve two columns from the same table, but only if a certain column in the current row isn't set. With just one column to retrieve, there is no problem. Once I need another column, it appears that I need another subquery with another case-clause, but that seems really ineffective. I've never used Joins before, but I'm thinki...

How should I query MySQL and how to cache the results from MySQL?

I have managed finally to get Solr working, with the help of all you guys, so THANK YOU! And I have to say, I now understand why you recommended it, it's really powerful. Now, to the issue... I have indexed all "Searchable" information into Solr, and my plan is to query Solr, and then get the ID:s of the query-results (of all records t...

Can you use Cacti to monitor MySQL on Amazon's RDS?

I noticed that the instructions to setup cacti with mysql mention granting SUPER priveleges: Create a MySQL user with the SUPER and PROCESS privileges on each server you want to monitor However, it looks like using the Relational Database Service from Amazon (RDS), you cannot grant SUPER privileges. Does this mean I can't use cact...

Making sure a PHP array has only sequential keys.

Is there any way to have an array with items like: $array[1]; $array[3]; $array[4]; Be turned into an array like this: $array[1]; $array[2]; $array[3]; So that the array has only sequential numeric keys? Thanks! -iMaster ...

What's the most efficient way to get the horizontal average in a MySQL query?

I have the following MySQL-table Id | One | Two | Three ---------------------------- 1 | 10 | 30 | 20 2 | 50 | 60 | 20 3 | 60 | NULL | 40 Edit: Of course the table doesn't need to be NULL by default, but I don't want it to affect the average (so the average is calculated as 50 and not 33,33). I want tha...

Character encoding problem in PHP/MySQL/jQuery

Hello! I made some CMS in PHP which manipulates with data from MySQL. In my CMS, i have some input fields in which I would like to have jQuery's fancy autocomplete implemented. Basically, the idea is to create jQuery's arrays from MySQL tables... I'm working with PHP 5.3.0, MySQL 5.0.82 and Eclipse 3.4.2. My PHP project in Eclipse is UT...

Inserting email headers into mysql field quotes and slashes issue

I am trying to insert email headers read from impap in to a mysql text field. Problem is the headers are full of slashes, commas, quotes, line feeds. mysql_escape doesnt come near it. The different mail server responses can lead to quite different headers. Do i have to do some weird voodoo before storage? ...

Problem with MySQL ORDER BY - can I use natsort to fix it?

I need to use natural sorting with a MySQL result since it currently sorts my INT values as follows: 1 123 1256 22 231 [etc] While I would need it to sort like 1 22 231 1256 I know of the "natsort" function, but it does not work for a MySQL query result. How can I sort (naturally), is it possible to do this within the query? Th...

mysql timediff to hours

Hi, I'm Trying to get the timediff from my table and convert it to hours (it's for an hourly billed service) SELECT TIME_TO_SEC(TIMEDIFF(endDate,startDate))/3600 FROM tasks > where endDate and startDate are in datetime format is there another way (more efficient) to do this task? Thanks ! ...

mysql database automatic partitioning

I have a mysql database table that I want to partition by date, particularly by month & year. However, when new data is added for a new month, I don't want to need to manually update the database. When I initially create my database, I have data in Nov 09, Dec 09, Jan 10, etc. Now when February starts, I'd like a Feb 10 partition automa...

Selecting from a MySQL DB based on parts of a timestamp.

Is there a way to select rows from a DB where the timestamp is in a certain year? I don't have a specific timestamp, just a range (ex. all timestamps within the year 2009). Is there a way to do this? How else might I go about doing something like this? Thanks for your help! -iMaster ...

Is there a MyPHP project much like MyPerl?

Here: http://freshmeat.net/projects/myperl/ I need to enable PHP in MySQL ...

most efficient way to print a list of names based off a csv using php and mysql

I have an array of player's IDs. There will generally be about 5 players, not likely to be more then a dozen: $cplayers= array(1,2,5); I want to display the players names as a list. $query = "SELECT username,id FROM users ORDER BY id"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $playercoun...

SQL Design Pattern: how do I store multiple unique ids from different sites in mashup?

I'm building a mash-up to store meta-data on items from multiple REST API datasources. I'd like to be able to generate typical feeds (most recent, top rated, most viewed, etc) based on data summarized across all the different datasources, and also add tags (i.e. many-to-many relationships). My problem is that each datasource has a diffe...