mysql

Possible to get the code powering a view in MySQL?

Well I'm a bit of an idiot, I wrote a view then accidently closed the window so now I don't have a copy of the query powering it. Syntax was: CREATE VIEW view_name AS SELECT something FROM somewhere Is there a way to get the "SELECT something FROM somewhere" or am I going to have to rewrite it from memory? ...

Easiest way to create a virtual LAMP machine on Windows XP?

I need to set up a test environment on my XPSP3 machine that runs Apache, MySQL, and PHP. My original test environment was an old box that ran those three under Win2k. That box died. Running on Windows was never optimal because the ultimate hosting environment is CentOS Linux. What is the most straightforward way to set up a virtual mac...

JPA EntityManager find with case sensitive key

I'm trying to use the JPA EntityManager find() method. My primary key is a string which corresponds to a user's name. I am using JPA / Hibernate / MYSQL. My problem is a search for user 'David' matches user 'david' due, I assume, to the case insensitive string matching in the underlying MYSQL. This causes me a whole heap of problems!...

Best way to prevent a value from going negative in mysql

Hi all, We have a table that maintains account balances by recording transactions in that table. i.e. the most recent row is the account balance. When recording a withdrawal, we would like to ensure that the balance can never go negative. Our proposed solution is something like: INSERT INTO `txns` (`account_id`, `prev_balance`, `tx...

PHP & MySQL compare password

How does one check to see if a user has typed in the right password to log in? This is what (out of a bunch of combinations...) I am doing: <? $login = $_POST['login']; $password = $_POST['password']; mysql_connect('localhost', 'root', 'abc123'); mysql_select_db('aun_vox') or die(mysql_error()); $q = mysql_query("SELECT password FR...

Tinyint vs Bit

I don't want to touch-off a religious war here, but there seem to be two schools of thoughts in how to represent boolean values in a database. Some say bit is the appropriate data type, while others argue tinyint is better. The only differences I'm aware of are these: bit: storage size is 1 bit, possible values are 0 or 1 tinyint: sto...

How to Sum Columns From Two Result Sets in MySQL

I have the following table: ratings: ID | post_id | rating_type The rating_type field is either 'thumb-up' or 'thumb-down'. I want to get a result set telling me what the highest rated posts are. The following query gives me a result set with the number of up votes for each unique post_id. SELECT COUNT(post_id) as number_up, post_...

MySQL - ERROR 1045 - Access denied

In some way I have managed to get this error when I try to access into MySQL via the command line: [root@localhost ~]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) I have tried resetting the password without any luck using this HowTo. I have uninstalled mysql com...

unique fields with size issue

I've got a mysql database and I'm trying to put a url and unique id into two seperate fields. One of the urls are sometimes more than 800 characters long. I tried to create a UNIQUE index of the id and url, so that I'm not linking to the same url/id combo more than once, but I get an error regarding field length for the index. I'm cur...

script to convert mysql dump sql file into format that can be imported into sqlite3 db

hi, i have an export sql file containing tables and data from mysql and i want to import it into a sqlite 3 db. please can you tell me the best way? i get error reading file in via sqlite3 binary. ...

Convert Oracle stored procedure using REF_CURSOR and package global variable to Postgresql or MySQL.

This package uses two unique features of Oracle, REF_CURSOR and a package global variable. I would like to port the functionality from Oracle to Postgresql or MySQL. PACKAGE tox IS /*=======================*/ g_spool_key spool.key%TYPE := NULL; TYPE t_spool IS REF CURSOR RETURN spool%ROWTYPE; /*=======================...

Connecting to MySQL with Python 2.6...how?

All my searches, including this question on Stack, point me to MySQLdb. Unfortunately MySQLdb doesn't have a version for Python 2.6. What am I to do? ...

MySQL add total column

I need to query this DB to get each row, but also the SUM of one of the column values of the results. I could use php to get the total value, but then I'd need to run two loops, one to get the total (which goes at the top above the results). So I'd prefer the query to catch it and just make a "total" row, but the only way I've gotten it ...

How to create PHP database-driven reports

How can I produce printable reports from a database? I need to print 1 or two reports per page with about 300 reports. I'd prefer free methods; I don't want to pay for a big report generator. ...

PHP array problem

Hello. I'm sending some data over AJAX to a PHP file. It's about filter options. Anyway, I am sending it like this: filter[0][data][type] string filter[0][data][value] automobiles filter[0][field] product filter[1][data][type] numeric filter[1][data][value] 6000 filter[1][field] price This above is taken from FireBug console. Then,...

How to design a movie database?

Hi Guys, I'm trying to get my head round this mind boggling stuff they call Database Design without much success, so I'll try to illustrate my problem with an example. I am using MySQL and here is my question: Say I want to create a database to hold my DVD collection. I have the following information that I want to include: Film Tit...

Build a table at runtime in Ruby on Rails

How would I go about creating multiple database tables at runtime that utilize the same model given that rails wants to infer the table name from the model name? I want to be able to create a new object based on a model, then create a new table with a unique name that the object will reference. Does anyone have any examples or advice t...

how does one rename a schema in MySQL

Hi I am using mysql 5.0.x How do I rename a schema? ...

if i use LIMIT on a mysql query, should the result set be equal to the limit?

for example will select * from table limit 0,5 return at most 5 rows or must it find exactly 5 and if the row_count doesnt equal 5, it returns an empty result set? what if the query was select * from table limit 5? ...

Creating an isset if fuction using php to avoid and update if the input is empty for a MYSQL update.

Hi I am newish to php and I have created an update page for Content Management System. I have a file upload in this case a picture. I have other inputs that contain text and I can get them to populate my form and thats fine and works great because the user can see what has already been entered. But the file name for the photo can not hav...