mysql

MySQL count row

hi all, how can I count row based on its contents? assumed I have table like this [table a] ID_COMPANY | NAME ----------------------------- A1 | COMPANY A [table b] ID_COMPANY | USER | TYPE -------------------------------------- A1 | USER A | MANAGER A1 | USER B | DEP...

mysql restore for files on another server

Hi, I have a test database on a separate remote server than my production DB. Every once in awhile, I want to try and test things by uploading a copy of my production DB to my testing DB. Unfortunately, the backup file is now half a gig and I'm having trouble transferring it via FTP or SSH. Is there an easy way that I can use the mys...

CakePHP integration with ExtJS 3

Hello, I am a PHP and ExtJS user. I am looking into developing an application using a good PHP framework (CakePHP; good as in "I consider this good for me") and ExtJS version 3. What I would like to achieve is a complete Ext viewport with many grids and functions that would call PHP urls for retrieving data, saving data, edit/remove data...

How to get the query plan from a prepared statment

I don't remember ever seeing a way to use prepared statements from the console and somehow don't think running an explain query thought as a prepared statement from the API will get what I want. This is related to this old question of mine. I'm primarily interested in MySQL but would be interested in other DBs as well. ...

mysql combine query

need help, how can we combine these query? ive a problem in join statement.. SELECT hc.id_company, hc.name, hc.email, dc.country, dc.date_join, sum(if(ha.type='ADMIN',1,0)) as ADMIN, sum(if(length(ha.type)=6,1,0)) as STAFF, sum(if(ha.type='CUST',1,0)) as CUST from h_company hc, d_company dc JOIN h_adminstaffcust ha USING (id_company...

How to convert mysql table data to Excel or CSV format in CakePHP?

Hi, I want to convert my sql data to csv files while clicking on a button. The code fragments I found for sql to CSV conversion were in PHP, and I'm trying to convert it to CakePHP since I'm working in CakePHP. Here is the PHP code I'm tring to convert: $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($...

How to encrypt database in symfony

I work with symfony framework and Propel and i was wandering what is the easiest way to encrypt a database. I'm not talking about passwords but all the database . I built a small web application for a client that manages some information (user accounts, passwords etc) and i don;t want it to be visible if someone has access to phpmyadmin ...

Need to Get Data from a table which contains unique id with different category in mysql

Hello all, My Table Structure is: artist_id category 1 Song 1 Song 1 Song 1 Video 1 Video Now, my output must be id category total 1 Song 3 1 Video 2 How this can done by using MYSQL. ...

Need table code design for recommend user profile function

Hi guys, I have a simple social network project going and I would like to add a simple recommend this user profile function. A logged in user can 'recommend' a user once - its just like the 'This ansewr is helpful/not helpful' buttons here on posts in Stackoverflow. I want a simple table design to implement the exact idea - any tips? A ...

How to union queries from the same table in MySQL

Hi all. I have two sets of results: SELECT name, count(appearance) as countA from table where results = '1' SELECT name, count(appearance) as countB from table where results = '2' And I wanted to combine them side by side, like this: +---------+---------+---------+ | col_1 | countA | countB | +---------+---------+---------+ | Jo...

What's wrong with the MySQL DATE() function?

I've had some bizarre results from queries I've been testing out with the DATE function, culminating in these little beauties: mysql> SELECT id FROM job WHERE DATE(due)=CURRENT_DATE; Empty set (0.00 sec) mysql> SELECT id FROM job WHERE DATE(due)=CURRENT_DATE AND id>2022; Empty set (0.00 sec) mysql> SELECT id FROM job WHERE DATE(due)=C...

Best database engine for huge datasets

I do datamining and my work involves loading and unloading +1GB database dump files into MySQL. I am wondering is there any other free database engine that works better than MySQL on huge databases? is PostgreSQL better in terms of performance? I only use basic SQL commands so speed is the only factor for me to choose a database ...

Subcategories MySql and php

Hi, I'm having troubles with subcategories. I want to display this on my page with 1 sql query: Category 1: Sub cat 1 Sub cat 2 ... Sub cat n Category 2: Sub cat 1 Sub cat 2 ... Sub cat n Category 3: Sub cat 1 Sub cat 2 ... Sub cat n ... Table schema: categories id | catname | description subcategory id | pare...

How do I get all of the latest "versions" from my table with one MySQL query?

I have a table with the following basic structure. unique_id | name | original | version ----------------- 1 | a1 | 1 | 1 2 | b1 | 2 | 1 3 | a2 | 1 | 2 4 | a3 | 1 | 3 5 | c1 | 5 | 1 6 | b2 | 2 | 2 Now it should be obvious from this that there is a form of version control, where we keep track of the original document, and also tra...

Mysql Stored Procedure Issue

When creating the following procedure I receive this error message: ERROR 1064 (42000): 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 'd_query; set d_result = execute stmt; deallocate prepare stmt; ' at line 15 But after checking I can't see the ...

MySQL Comparison Binary Collation vs Binary Strings

according to mysql certification guide, comparisons between binary collation vs binary strings are different because comparisons in binary collation is done per character vs per byte in binary strings. but what difference does that give? ...

What are the essential dba skills a developer should learn?

Creation of objects like tables and indexes are fairly essential, even if the code has to be authorized or created by the dba. What other areas normally carried out by dbas should the accomplished developer be aware of? ...

MySQL Timestamp Question

i am looking at some practice questions Assume that you've just created this table: CREATE TABLE timestamptest ( ts1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, i INT ); When you look at its structure, you will notice that the TIMESTAMP column is declared NOT NULL. What happens if you insert these records: mys...

Count of consecutive not null values

The count should be 3 and 1 in the following query. The count should be of the points earned consecutively. So once the user fails to earn any points, the count restarts. mysql> select name, count(*) from sortest group by name, (points = 0) OR (points is NULL) having name= 'john'; +------+----------+ | name | count(*) | +------+-------...

Multiple Counts in CakePHP

I have a PHP application using CakePHP. I need to present a table showing the count of particular events for each day of the month. Each event is record in the DB with a name and a Data. What is the best way to create a table for this, do I really need to do 31 SQL calls to count the events for each day, or take out the data for the whol...