mysql

MySQL vs PHP when retrieving a random item

Hi, which is more efficient (when managing over 100K records): A. Mysql SELECT * FROM user ORDER BY RAND(); of course, after that i would already have all the fields from that record. B. PHP use memcached to have $cache_array hold all the data from "SELECT id_user FROM user ORDER BY id_user" for 1 hour or so... and then: $id = ar...

mysql select from a table depending on in which table the data is in

I have 3 tables holding products for a restaurant. Products that reside in the bar, food and ingredients. I use php and mysql. I have another table that holds information about the orders that have been made so far. There are 2 fields, the most important ones, that hold information about the id of the product and the type (from the bar,...

Is it possible to extract a script from an MySQL database to create a copy of the tables on another MySQL database?

Is it possible to extract a script from an MySQL database to create a copy of the tables on another MySQL database which is located on a remote server? ...

mysql full text search ampersand (&) Problem

How can I serach word with "&" using mysql full text search ? There are words string, like "Marks & Spencer", "at&t" in my tables , serach "at&t", but can't find it on the database using mysql full text search Any ways to serach word with "&"? ...

De-normalization alternative to specific MYSQL problem?

I am facing quite a specific optimization problem. I currently have 4 normalized tables of data. Every second, possibly thousands of users will pull down up-to-date info from these tables using AJAX. The thing is that I can predict relatively easily which subset of data they need... The most recent 100 or so entries in those 4 normali...

One on One table relation - is it harmful to keep relation in both tables?

I have 2 tables that their rows have one on one relation.. For you to understand the situation, suppose there is one table with user informations and there is another table that contains a very specific informations and each user can only link to one these specific kind of informations ( suppose second table as characters ) And that cha...

please help me in this complex mysql query

i have answers table ( ans_id , question_id , ans_date) and answers_votes table (vote_id , user_id , ans_id , vote = 1 or -1) i want select from answers that have the big sum(vote) of vote that posted today this mean have today date in ans_date ...

MySQL SUM Query daily values of a week problem

Am trying to return the sum of each day of a week in mysql but it returns nothing despite having values for the 3rd Week of March 2010 SELECT SUM(expense_details_amount) AS total FROM expense_details WHERE YEAR(expense_details_date) = '2010' AND MONTH(expense_details_date) = '03' AND WEEK(expense_details_date) ...

How to create a relation between two tables using PHPMyAdmin?

How to create a relation between two tables using PHPMyAdmin? ...

How can I protect this code from SQL Injection? A bit confused.

I've read various sources but I'm unsure how to implement them into my code. I was wondering if somebody could give me a quick hand with it? Once I've been shown how to do it once in my code I'll be able to pick it up I think! This is from an AJAX autocomplete I found on the net, although I saw something to do with it being vulnerable to...

Unknown column '' in 'field list'

I am running a sql in PHP query that is dieing with the mysql_error() of Unknown column '' in 'field list' The query: SELECT `standard` AS fee FROM `corporation_state_fee` WHERE `stateid` = '8' LIMIT 1 when I run the query in PHPmyadmin, it return the information without flagging the error EDIT: I apologize for not posting enough...

php date formatting with MySQL SHOW TABLE STATUS

probably missing something simple: <?php $con=mysql_connect('localhost','xxx','xxx'); $db=mysql_select_db('xxx'); $sql = mysql_query("SHOW TABLE STATUS WHERE `name`=\"my_table\""); $foo=mysql_fetch_array($sql); return $foo['Update_time']; // returns 2010-03-31 16:51:06 ?> how do i format this. I tried using date('l jS F Y @ H:i...

MySql: Select all entries with count...

Hey guys quick question, I have a query that I want to count all entries it finds, and select all so when I use while($row=mysql_fetch_assoc($query)){ it will list all entries. The problem I am encountering is that while, all the entries are successfully counted and the right number is listed, only the latest entry is select and listed w...

mysql - how do I load data from a different configuration...

I'm not sure if this will make sense, but I'll give it a shot. My hard drive went down and I had to reinstall the os along with all my webserver configuration,etc. I kept a backup of the mysql database, but it doesn't contain all the tables...I added a couple tables after my last backup. I have access to the hard drive and the direc...

MySQL query (over SSL) fails in IIS 7 using default AppPool identity

I am trying to run a website locally in Windows 7 under IIS 7. I have the AppPool configured to use "Classic" mode, but connecting to a MySQL DB that requires SSL fails. If I change the identity to my user account it works perfectly. It fails when using the default "ApplicationPoolIdentity" account. Is there something I'm missing somewhe...

select, delete & update from multible tables using a single query in mysql

for example i use following command to find a record SELECT `users`.`mail` FROM `users` WHERE `users`.`uid` = %s if found an match, then i should like to delete this record, and update in the same query an another table. i can solve this with 'joins' ? ...

Is it a good idea to Strtolower the username then store it in database?

Hi, In a php/mysql application where people can registre, is it a good idea to strtolower the username then store in the database in order to not have problems in the future? because people are using DiFfeReNt cases and i'm afraid that will make conflict in some queries. Thanks ...

SQL Joining Two or More from Table B with Common Data in Table A

NOTE: EDITED The real-world situation is a series of events that each have two or more participants (like sports teams, though there can be more than two in an event), only one of which is the host of the event. There is an Event db table for each unique event and a Participant db table with unique participants. They are joined together...

Using MySQL variables in a query

I am trying to use this MySQL query: SET @a:=0; UPDATE tbl SET sortId=@a:=@a+1 ORDER BY sortId; Unfortunately I get this error: "Parameter '@a' must be defined" Is it possible to batch commands into 1 query like this, or do I need to create a stored procedure for this? ...

MySQL auto increment

Hi, I have table with an auto-increment field, but I need to transfer the table to another table on another database. Will the value of field 1 be 1, that of field 2 be 2, etc? Also in case the database get corrupted and I need to restore the data, will the auto-increment effect in some way? will the value change? (eg if the first row,...