mysql

How do i add foreign keys to two Innob tables so that they autoupdate each other?

I have two tables users and lead_contacts which have similar data. When somebody buys a product they become a user. How should I modify the two create staements below so: that the leads table receives a new entry with first_name, last_name, company and email, when a user is created. the first_name, last_name, company and email in use...

Warning: mysql_connect(): Can't connect to local MySQL server

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11) in /home/aa/public_html/bb/db.php on line 2 Could not connect: iam getting this error but the problem is that this error comes irregularly,sometimes it didnt come all the day and sometimes it comes countless times. what could b...

MySQL Field Length Errors

Just moved a site over to a new server and we started getting some errors. Mainly that some data we were passing into a MySQL table was too long for the field. Having checked through the DB it seems the old server was truncating the data to fit the table, yet the new server throws a TEP STOP. Any ideas what the setting is to switch this ...

MYSQL Updating multiple fields from fields of another table

Scenario: I have an application that has a config table which stores the config data for each website thats uses the application. I have added a couple of extra columns to the config table and rolled this out to all applications. I have since updated these new columns with data that needs to be the same on all the config tables. How wo...

retriving CURTIME() from server by adding 3hrs and show it in PHP page

Hi, How can I retriving CURTIME() from server by adding 3hrs and show it in PHP page. Thanks in advance. ...

How do I create a Django model with ForeignKeys which does not cascade deletes to its children?

One of my models which has ForeignKey's is actually a MySQL view on other tables. The problem I'm running into is that when I delete data from these tables, Django, as described in the "deleting objects" documentation... When Django deletes an object, it emulates the behavior of the SQL constraint ON DELETE CASCADE -- in other ...

Fastest distance lookup given latitude/longitude?

I currently have just under a million locations in a mysql database all with longitude and latitude information. With this I use another lat/lng to find the distance of certain places in the database but it's not as fast as I want it to be especially with 100+ hits a second. Is there a faster formula or possibly a faster system other th...

MySQL "Not IN" query suddenly stopped returning results

I'm doing some work for a site on a shared hosting environment that has a history of flipping settings on us. This week, an update script suddenly stopped working, and the underlying reason is that a NOT IN clause that used to return results is no longer doing so. The query, in its essence, is this: SELECT * FROM db1.entry where entr...

How can I structure a table so that the field remains atomic?

I have a shopping cart in which I have to keep track of stock, and this includes stock with attributes. For example: shirt -- blue, small = 50 -- blue, medium = 22 -- blue, large = 53 -- red, small = 15 etc... These fields are currently separated by commas in the database and the IDs would be as follows: 1,3 1,4 1,5 2,3 wh...

Why are batch inserts/updates faster? How do batch updates work?

Why are batch inserts faster? Is it because the connection and setup overhead for inserting a single row is the same for a set of rows? What other factors make batch inserts faster? How do batch updates work? Assuming the table has no uniqueness constraints, insert statements don't really have any effect on other insert statements in th...

How to calculate percentile rank for point totals over different time spans?

On a PHP & CodeIgniter-based web site, users can earn reputation for various actions, not unlike Stack Overflow. Every time reputation is awarded, a new entry is created in a MySQL table with the user_id, action being rewarded, and value of that bunch of points (e.g. 10 reputation). At the same time, a field in a users table, reputation_...

parse XML and insert data in MySQL table

Hello everyone I am trying to parse a xml file that i have (using javascript DOM). and then i want to insert this data in a mysql table (using php). I know how to parse xml data. But i am unable to figure out how to use php and javascript together and insert data in mysql table. Kindly help me in this. Best Zeeshan ...

Delphi - Save DateTime Null to DB (ADO / MySQL)

Hi, i have a delphi form with some DB Controls on it. To represent a date I use the TJvDBDatePickerEdit (from JCL), which has a nice property ShowCheckBox := True; to allow the user to enter that no date is known (DBNull). I verify, that nulling the DatePicker works as expected by: procedure Tframe.adoQueryBeforePost(DataSet: TDat...

Illegal mix of collations MySQL Error

I'm getting this strange error while processing a large number of data... Error Number: 1267 Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' SELECT COUNT(*) as num from keywords WHERE campaignId='12' AND LCASE(keyword)='hello again 昔 から ある å ´æ‰€' What can I do to re...

Retrieving the index of an inserted row

I'm trying to keep the database tables for a project I'm working on nice and normalized, but I've run into a problem. I'm trying to figure out how I can insert a row into a table and then find out what the value of the auto_incremented id column was set to so that I can insert additional data into another table. I know there are function...

Most efficient way to store URLs in Mysql?

I want to store a large set of URLs in MySql and create a unique index on the column. If I make the column utf8 then I'll be limited to a varchar(333), which is not enough to hold some of my URLs. If I declare the column to be latin1 then I get the full 1000 characters (don't think I need that much). However, I'll have to encode the U...

Temporary permission to view photos and albums

I'm making a gallery website. Photos and albums should be hidden from the public by default, but the owner can share a public URL if he wants. I also want to use short URLs for this. I'm trying to figure out the best way to do this. At first I thought I could have a MySQL table with the short URL code (something like Zneg8rjK), and the...

Missing Database Table Cakephp

Error: Database table users for model User was not found. I'm expriencing the error show above and I'm unsure why this is happening. I've searched for a possible solution to this problem and the most prevalent solution is... going to the app/tmp/cache directory and removing the files in the model and persistent folders. I've done that...

MySQL: @variable vs. variable. Whats the difference?

In another question I posted someone told me that there is a difference between: @variable and: variable in MySQL. He also mentioned how MSSQL has batch scope and MySQL has session scope. Can someone elaborate on this for me? ...

Calculating a date

I need to make a timestamp to put into MySQL. The user is submitting a number (of weeks) I need to add that many weeks to today's date. What I am trying to do is calculate an end date of an ad that the user is submitting. Any suggestions on how to do this? Thanks! ...