mysql

How to add "weights" to a MySQL table and select random values according to these?

Hello, I want to create a table, with each row containing some sort of weight. Then I want to select random values with the probability equal to (weight of that row)/(weight of all rows). For example, having 5 rows with weights 1,2,3,4,5 out of 1000 I'd get approximately 1/15*1000=67 times first row and so on. The table is to be filled ...

Use of parameters for mysql_query

somewhere while studying I juz found out something interesting.. It says something as follows: $query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",mysql_real_escape_string($firstname), mysql_real_escape_string($lastname)); using the query like this instead of $query="se...

How is Twitter's MySQL database architecture designed? Try your best.

No one knows. And even if you work at Twitter, you probably won't let us know the secret. So, let us all post our theories on how this communication tool database is designed! It definitely can't follow the standard replication architecture, right? It's got to do some sharding, partitioning, etc, etc. Let me know what you think! ...

Testing framework for data access tier

Is there any testing framework for Data access tier? I'm using mysql DB. ...

Error when connecting to MySQL using PHP/PDO

My code was working all fine yesterday and today it suddenly just don't want to connect to my database. I have changed no settings on it or on the code and I haven't updated any software either. All I do is this: new PDO('mysql:host=localhost;port=3306;dbname=test', 'username', 'password'); And I get a nice exception message saying t...

Is this way of doing this the 'better way' ?

I have a advertisement website with alot of records stored in a mysql db. On my main page, I have a form where users may specify their search criteria. Action is set to myPhp.php file. myPhp.php contains NO HTML, only php code, and it is basically something like this: 1- get values from FORM and build a SQL query 2- query MYSQL db. 3...

MySQL database structure: more columns or more rows?

I'm creating an online dictionary and I have to use three different dictionaries for this purpose: everyday terms, chemical terms, computer terms. I have tree options: 1) Create three different tables, one table for each dictionary 2) Create one table with extra columns, i.e.: id term dic_1_definition dic_2_definition dic_...

How to store tags in MySQL tags, one field in total or one filed for each tag?

I am developing a product which is close to stackoverflow.com. A poster is required to enter tags for his problem or task. How to store these tags in the database, one field(column) in total or one field(column) for one tag? ...

Plotting graph with FLOT using mysql and ajax

I am trying to use flot to plot some data that is pulled from a MySQL db. I am log users login visits and I have a SQL function that will retreive the number of visits per day for a given month, getStats($day). I have read some examples online how to properly do this but for some reason when I try and graph the array data in my javascrip...

Silverlight deploy website with db on host not working

Hello, i have built (locally) a silverlight website. It uses a mysql database (had to install mysql connector) and a wcf service to contact the db on the server. Locally, everything works fine. However when i uploaded it on my host, the silverlight application loads OK, but t cannot get the data from the host database. It's the first ...

MySQL - Is there a way to match a table data to a given string rather than vice versa.

SELECT * FROM disney; +++++++NAME+++++++ lion king cinderella the little mermaid +++++++++++++++++++ $string = "i love the movie lion king, it rocks!" I want to get the NAME from disney where the NAME is inside the given string. It's kinda like: 'SELECT * FROM disney WHERE NAME LIKE "%'.$string.'%";' only the other way around (but ...

What is the best way to query a datetime field against date fields?

Hi, I just want to know what you guys are doing when you have a datetime field, ie: Game.first.starts_at => Thu, 03 Dec 2009 20:20:00 EST -05:00 And you want to query it against a date field: 3.days.from_now.to_date.to_s(:db) => "2009-12-03" Currently I make this work by using the B...

Creating/dropping MySQL databases with integer names

How to create/drop databases which have integers as their names, from the command line? Using GUI clients, I can create/drop them fine. However, 'create/drop database' does not seem to work because the names are integers. Using GUI clients is fine with me, but curious to know: are there any workarounds to do this in command line? Not...

Set Current Database in MySQL Script

I have a script file for MySQL that needs to be run on about 30 databases. Here's a snippet: ALTER TABLE <whatever_database>.`tblusers` ADD COLUMN `availability` ... ALTER TABLE <whatever_database>.`tblusers` ADD COLUMN `reliability` INTEGER ... There are many more lines in this script and I'd like to automate it in a loop of current...

Whats wrong with this CREATE TABLE statement?

CREATE TABLE findings ( ident VARCHAR(28), code VARCHAR(8), when DATETIME, ip VARCHAR(15) ); ...

sqlalchemy does not create my foreign key

SqlAlchemy newbie question: Base = declarative_base() class A(Base): __tablename__ = 'as' id = Column(Integer, primary_key=True) class B(Base): __tablename__ = 'bs' id = Column(Integer, primary_key=True) a = relation(A) When I create my database schema, I have two tables, as and bs, which have one column (id) but...

Can MySQL .NET Connector 6 Be Used w/ Entity Framework 4?

Does anyone know if the MySQL .NET Connector 6 can be used w/ the Entity Framework 4 in Visual Studio 2010 Beta 2? ...

MySQL: SELECT statement with Chinese and Japanese characters (empty result?)

I'm trying to query my database to get some results in Chinese and Japanese languages as follows: $str = '日本'; $get_character = mysql_fetch_array (mysql_query("SELECT id FROM `mytable` WHERE ch = '$str'")); print $get_character[0]; The problem is it returns me nothing. For testing purpose I've changed 日本 in database to test and I do ...

MySQL decimal(10,2) Increase By 10%

I have a column with data type decimal(10,2). I want to increase all of the current values by 10%. Thanks. ...

Conditional limit in mySQL query possible???

Hi everyone, i am faced with a decicion regarding handling threaded comments in our project... I have a simple MySQL table which holds all the comments. There are two types: parents and childs. Childs represent a reply to a parent or another child. My problem: -Comment (depth 0) -- Reply Child (depth 1) --- Reply to previous child (de...