mysql

Is Data Mapper a more modern trend than Active Record

I've come across a couple of ORMs that recently announced they are planning to move their implementation from Active Record to Data Mapper. My knowledge of this subject is very limited. So a question for those who know better, is Data Mapper newer than Active Record? Was it around when the Active Record movement started? How do the two r...

Execute MySQL Stored Procedure using Command Line

Hi, Please help me out to execute a MySQL Stored procedure in command line, where the procedure contains conditional statements.. ...

How to check in batch script if "mysqldump" and "mysql" commands succeeded or not ?

I'm running mysqldump and mysql commands from a batch script on Windows to make a backup of a database and restore it. How could I check in the batch script whether these commands executed correctly or end up with error ? In case of error, I would like to know what the error is. Thanks ! ...

Syntax error in MySQL WITH ROLLUP query?

Any idea why the following query syntax is wrong: SELECT year, sum(profit) FROM BASEDATA b group by year WITH rollup Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near..... MYSQL Version 5.0.77-community-log ...

SQL UPDATE not working?

In my LAMP application (using CodeIgniter), I have a call to $this->db->update... that generates a SQL like the following: UPDATE `MyTable` SET `MyProcess` = 5 WHERE `Id` = 1 The problem is that this seems to work intermittently -- and I currently have no idea what might be wrong. Is there anything about MySQL I need to know about whe...

Break up data from one column into multiple columns in a new table (MySQL)

I have a table full of data, where one column is full of different entries for each row, where the data is formatted like this: A:some text|B:some other text|C:some more text| I want to separate those strings of text into two columns on a new table. So the new table should have one column for A, B, C etc. and the other column will have t...

how to insert data to two tables at the same time?

Hi Guys, I have this problem in my system, i need to register a patient to the system, patients reference_number is used to make a reservation in the hospital. problem i got is when a patient is registered to the system a reservation is made at the same time, i need to update two tables, patient table and reservation table, i have to ta...

Insert php value into mysql table

https://docs.google.com/document/edit?id=1dL_Q2dAo4DuyaS9rVGM5tVPXW8vWZYOvrcfSbnOD-uk&hl=en $num = $_GET['p']; echo "Number: ".$num." Other: ".$Other; ?> How to insert ".$num." into mysql_query("UPDATE `grass` SET `$num`='{$_POST['c2']}' "); } ...

Mysql INSERT Statement Differences

I normally found three ways of using MYSQL insert Command INSERT INTO `table` (field1, field2, field3) VALUES ('value1', 'value2', 'value3'); or INSERT INTO `table` VALUES ('value1', 'value2', 'value3'); or INSERT INTO `table` SET `field1`='value1', `field2`='value2', `field3`='value3'; Is there any differences among these? ...

Why use COALESCE() in sql statement

Hi, I'm refactoring some old code and stumbled upon this named query (It's using hibernate on top of mysql): delete F from foo F inner join user DU on F.user_id = DU.id where (COALESCE(:userAlternateId,null) is null or DU.alternate_id like :userAlternateId ) and ( COALESCE(:fooId,null) is null or F.foo_id like :fooId ) and ...

MySQL InnoDB doubled IDs

Hello all! http://img839.imageshack.us/img839/8241/stackoverflow.png I created a new databese. There are 2 tables class and teacher. There is a field class_leader in the table class related with teacher_id from teacher. [1] In PHPMyAdmin relationship looks like: [2] Table teacher contains some records. [3] When I add new records at ...

Save mysql query to excel file from php webpage

Hi, I have a table within a mysql database. What i want to do, is in a php page, run a select statement and output the result into an excel file. I've seen quite a few tutorials out there and tried them, however these output the contents of the webpage into the excel file. I just want the mysql table data and headers. Is there a wa...

Select with two counts on same column

I have two select queries: SELECT MONTH(date) AS month, count(DISTINCT ip) FROM table_name WHERE field = 1 GROUP BY month and SELECT MONTH(date) AS month, count(DISTINCT ip) FROM table_name WHERE field = 2 GROUP BY month how can I write one query to select SELECT MONTH(date) AS month, count(DISTINCT ip) [ for field = 1],...

mysql query sum based on years

i friend i have a database table amount_id, year, amount, and data like this 1 2002 2 2 2002 3 3 2007 2 4 2004 6 5 2004 10 i wan to run a query to select data like this 2002 4 2007 2 2004 16 thanks for help ...

Creating functions in mysql doesnt work - Error 1064

I tried this example via phpMyAdmin http://www.databasejournal.com/features/mysql/article.php/3569846/MySQL-Stored-Functions.htm mysql> DELIMITER | mysql> CREATE FUNCTION WEIGHTED_AVERAGE (n1 INT, n2 INT, n3 INT, n4 INT) RETURNS INT DETERMINISTIC BEGIN DECLARE avg INT; SET avg = (n1+n2+n3*2+n4*4)/8; RETURN avg; ...

Is it generally acceptable to use a primary key as a the id of an HTML element?

I have an HTML list whose <ul> items have ids same as the primary keys in the database table. Is it generally acceptable to expose the primary keys for this purpose? If not, what efficient methods can be used to mask them? ...

Checkboxes Inserting Into MySql Database

Hi guys, I have a survey type form, and in a number of the questions, the user has the option to tick more than one box. I am storing these answers in a mysql database however at the moment, the database only stores the very last checkbox that is ticked. Is there anyway to store all the checked values, possible separated by a coma, o...

Storing a floating point number as an INT?

Hi guys, what would be the best data type to store a floating point number in mySQL? Can I somehow store it as an INT? I am thinking that VARCHAR is my best option, but if you guys know of anything better I would appreciate the input. Thanx in advance! ...

How can I get the entire result set of a query here?

Hi, I've written the following CodeIgniter model function to grab and iterate through a MySQL query result. function get_book_info() { /* * SELECT b.isbn, b.title, b.publisher, b.date, b.thumb, b.filename, b.pages, t.tag * FROM books AS b * INNER JOIN books_tags AS bt ON b.isbn = bt.book_id * INNER JOIN tags AS t ON bt.tag_id = ...

jQuery Connected Sortable Lists, Save to MySQL

Hello, I have a generated list of items (teams, playing in the season). I want to distribute these items to other lists (divisions for the season) and save new lists to MYSQL (order of list doesnt matter). I have to say that divisions may vary depending on the season, so i have divisions also generated from db. I changed #sortable to ....