mysql

How can I remove every column in a table in MySQL?

In MySQL, is there a way to drop every field in my table, short of using: ALTER TABLE `table` DROP COLUMN d1, DROP COLUMN d1, etc.... Almost like TRUNCATE for fields maybe? ...

Is it possible to achieve this selection with a single query?

This one has been haunting me for quite a while now.. I have been developing my own CMS using a MySQL database; each uploaded image is assigned to a category, according to which part of the site it is related to (I need to do this since each category has its own way to handle images). I have several tables for the various entities, an '...

Writing a single query for mutliple queries with same where condition.

select column1,column2,column3 from table1 where column5=0 and column6=0; select column4 from table2 where column5=0 and column6=0; These are two sql statements reading data from table1 & table2, is there a way instead of 2 single queries, can i write in a single query? Thanks. ...

How to select a period in mysql using the date field as a unix timestamp?

Hello friends, I have a table with a field where I store the date in unix timestamp, eg 1286515961. Need, select the records that are in the month, eg 'October 2010'. I would like to select records directly in mysql query, for speed, but using unix timestamp. Can anyone help me? Thanks already ...

Datetime or Timestamp for a MySQL field?

Hi, This one is a question I have asked myself several times, when creating Databases for PHP/MySQL web application. In Mysql, what'd you recommend between Datetime and Timestamp and why?. ...

PHP & MySQL - How should I allow my members to delete their membership from my site?

What is the best way to allow a member to delete their account if they wish to not be a member of our community? Should I simply have them click a delete button on the site? What other measures should I use? ...

Dealing with null values versus empty strings in a database when only empty strings are coming from the client via HTTP POST

My MySQL database has carefully defined fields. Some fields, if there is a chance that they can be unknown, allow a NULL value. I'm writing a web-based CMS to handle the data in said database. Obviously, the post arrays from the HTML forms never contain null values, only empty strings. I don't want to confuse the users of my CMS by ad...

What does "unsigned" in MySQL mean and when to use it?

What does "unsigned" mean in MySQL and when should I use it? ...

Select latest entry from MySQL database error

<?php mysql_connect("localhost", "user", "password") or die(mysql_error()); mysql_select_db("jmvarela_jacket") or die(mysql_error()); $query = 'SELECT * FROM `quote` ORDER BY `id` DESC LIMIT 1'; $row = mysql_fetch_array( $query ); echo $row['frase']; ?> I cant get this to work. I get this error: Warning: mysql_fetch_array(): s...

CSV Export/Import with PHPExcel

Hi Could you please guide me or provide me with some sample codes for performing CSV export and import using the PHPExcel library? Excel export and import is fine but I need csv export/import as well. I have other means of CSV export and import but can it be done via phpexcel also? Any kind of help is greatly appreciated. Thanks in ad...

How to have Android App communicate with external MySQL db

I am really confused on how to get data in and out of an android app from the internet. I imagined that i would store information in the mysql db on the server i already have set up. But from what I have read, I would need some type of in-between web service to make quiries with data sent from the app. Can anybody toss me some tips on...

Searching Database PHP Mysql

Hey, I know most of the time people just do a LIKE '%$search_query%' but see the thing is, in my case someone may be searching for things like that cow is fat now, the thing is in my database i wouldnt be storing it exactly as "the cow is fat" i'd be storing it something like "fat cow" so using LIKE '%$search_query%' wouldn...

MySQL self join question

Take a look at the following mySQL query: SELECT fname,lname FROM users WHERE users.id IN (SELECT sub FROM friends WHERE friends.dom = 1 ) The above query first creates a set of ALL the friends.sub's via the inner query, and then the outer query selects a list of users where user ids are contained within the set created by the inner q...

How to use MySQL JDBC driver in an SBT Scala broject?

When I run my project for the first time during an SBT session, it throws the following exception when trying to access a MySQL database: java.lang.NoClassDefFoundError: scala/Ordered When I run it again (and any time after it, during the same SBT session), it throws a different one: java.sql.SQLException: No suitable driver fo...

Mysql Full Text Search Issue Searching for Like

I'm doing the following query SELECT * FROM downloads WHERE MATCH (title, artist) AGAINST ('+like ' IN BOOLEAN MODE) ...and it's not returning any results when it should be. It's not the code or anything, since it works fine for any other search terms. Could it be the fact that like is commonly used in MySQL queries so it's i...

Distribute web traffic in X time.

I have different sources of web traffic and I serve ads to that traffic, now I need to code something to distribute for example X unique hits in Y time for ad with id Z. I want to be able to send X amount hits to an ad x hour, but I don't want to send all those hits in the first 10 minutes, and then wait 50 minutes to send traffic again...

PHP & MySQL security: one-way encryption Vs two-way encryption

Hi, I have read about using MySQL AES_ENCRYPT/AES_DECRYPT (two-way encryption) is less secure than using PHP - hash() (one-way encryption). http://bytes.com/topic/php/answers/831748-how-use-aes_encrypt-aes_decrypt Is it true that it is more secure that 'Rather than send the User his password, simply send him a link that he can click o...

How should joins used in mysql?

If i have two tables like user table-"u" userid | name 1 | lenova 2 | acer 3 | hp pass table-"p" userid | password 1 | len123 2 | acer123 3 | hp123 as for as i learnt from tutorials I can join these 2 tables using many joins available in mysql as said here If i have a table like role table-"r" ...

struts, hibernate, mysql - char encoding problem

Hello, I have a web app that gathers some data from the user and saves them to a mysql database. The problem is that for a String like "Ajánlat kiküldése", what gets stored to the database is "Ajánlat kiküldése". For my database, i have DEFAULT CHARACTER SET utf8. For my tables i have DEFAULT CHARSET=utf8. In my hibernate.cfg.xml i...

escaping hyphens with the mysql commandline tool

Is there a way to escape a hyphen with the mysql commandline tool? I basically need to do this: $ mysql -hlocalhost -uuser -puser information_schema -e "CREATE DATABASE foo-bar" Using mysqladmin is not an option due to the framework I'm within. ...