mysql

MySQL from Silverlight on Linux Server

I'm trying to access a MySQL database through Silverlight, and I know you can't do it directly, but the only way I know of is to use a WCF service. This won't run on the server I have, is there any other way to access the database (through PHP maybe)? ...

INSERT INTO ... SELECT ... vs dumping/loading a file in MySQL

What are the implications of using a INSERT INTO foo ... SELECT FROM bar JOIN baz ... style insert statement versus using the same SELECT statement to dump (bar, baz) to a file, and then insert into foo by loading the file? In my messing around, I haven't seen a huge difference. I would assume the former would use more memory, but the m...

mysql : possible to put IF statment in LEFT JOIN ?

Ok so i want to get an artists info from the db, but i want to know if they have any forthcoming events. To do this i need to traverse 2 tables, where events_artists is a 2 col link table... (this doesnt work but is what id like to do) SELECT art.*, events.event_id FROM art LEFT JOIN events_artists ON art.art_id = events_artists.art_i...

MOD_REWRITE HELP!

I want to use mode rewrite to display the following: mydomain.com/Florida/Tampa/ instead of mydomain.com/place.php?state=Florida&city=Tampa I've akready done this: (since I think it might make a difference!) mydomain.com/[name].html instead of mydomain.com/profile?user=[name] Here is the code! Options +FollowSymLinks Options +Indexe...

Why does this SELECT ... JOIN statement return no results?

I have two tables: 1. tableA is a list of records with many columns. There is a timestamp column called "created" 2. tableB is used to track users in my application that have locked a record in tableA for review. It consists of four columns: id, user_id, record_id, and another timestamp collumn. I'm trying to select up to 10 reco...

MYSQL multiple insert in codeigniter

Hi everyone, I know about the possibility of making a multiple insert in mySQL by doing something like this: foreach ($array as $manuf) { $sql[] = '("'.mysql_real_escape_string($manuf['name']).'", "'.$manuf['lang'].'", "'.$mId.'")'; } $this->db->query('INSERT INTO manufacturers (name, lang ,mid) VALUES ' . impl...

How do I delete every row except the last one for each day?

I have a table with stock quotes that looks something like this: id, date, stock_id, value Every day has several rows for each stock_id (it is automatically updated every five minutes), so the table is rather big at the moment. How do i delete every row but the last one each day for every stock_id? ...

Lock innoDB table temporarily

Hi everyone, I make bigger inserts consisting of a couple of thousand rows in my current web app and I would like to make sure that no one can do anything but read the table, until the inserts have been done. What is the best way to do this while keeping the read availability open for normal, non-admin users? Thanks! ...

How to exit after "MySQL server has gone away" error?

I have a cron job that runs every minute. Every once in a while the cron fails with the error: MySQL server has gone away The problem is that all the query below this error are executed and may sometimes give undesirable result. So how do I detect that the error has occurred and exit execution of rest of the code? Or any hint on...

combining two select statements to return one result

I need to combine the results for two select queries from two view tables, from which I am performing calculations. Perhaps there is an easier way to perform a query using if...else - any pointers? Essentially I need to divide everything by 'ar.time_ratio' under the condition in sql query 1, and ignore that for query 2. SELECT g...

PHP/MySQL Problem

Why does this only print the sites specific content under the first site, and doesn't do it for the other 2? <?php echo 'NPSIN Data will be here soon!'; // connect to DB $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('E...

mysql table creation problem..

Hi, I have a small problem. I am creating an appointment table where in the foreign key is patient id which is referenced from patient table.This table is for all registered patients. there will be unregistered patients also, who will be seeking appointments.SO i just need to store the name,phone and few details. I don't want ...

I have 2 MySql tables. How to get not all data from them in 1 sql query?

I have 2 MySql tables. users with id's and username's ; streams with userId's and streamId's How to get them as / join them into one table containing only username | streamId as SQL response? With one SQL query. ...

Complex query with two tables and multilpe data and price ranges

Let's suppose that I have these tables: [ properties ] id (INT, PK) name (VARCHAR) [ properties_prices ] id (INT, PK) property_id (INT, FK) date_begin (DATE) date_end (DATE) price_per_day (DECIMAL) price_per_week (DECIMAL) price_per_month (DECIMAL) And my visitor runs a search like: List the first 10 (pagination) properties ...

Remove duplicate records/objects uniquely identified by multiple attributes

I have a model called HeroStatus with the following attributes: id user_id recordable_type hero_type (can be NULL!) recordable_id created_at There are over 100 hero_statuses, and a user can have many hero_statuses, but can't have the same hero_status more than once. A user's hero_status is uniquely identified by the combination of r...

how to extract a column from mysql result set?

What would be the best way to extract a column out of mysql results set? My result set is like: [0] = ('id'=>1, 'name'=>a), [1] = ('id'=>2, 'name'=>b), [2] = ('id'=>3, 'name'=>c) How can I extract 'name' column as an array from this? I can do it using for loop. But wondering if there are any better reusable solution? ...

Need Insight - What is the best practice for syncing up a production database that will be used on a live site? CakePHP, Mysql

I have a site set up using CakePHP and MySQL and I want to work on a test database without disrupting my live site in case something goes wrong. I have another busy site, but my test site runs off the live database which can be occasionally nerve wracking. What do I do if I change a table name in the test db and I want it changed in th...

Need help with many-to-many relationships....

I have a student and faculty table. The primary key for student is studendID (SID) and faculty's primary key is facultyID, naturally. Student has an advisor column and a requested advisor column, which are foreign key to faculty. That's simple enough, right? However, now I have to throw in dates. I want to be able to view who their advi...

Prevent two users from editing the same data

Hi everyone, I have seen a feature in different web applications including Wordpress (not sure?) that warns a user if he/she opens an article/post/page/whatever from the database, while someone else is editing the same data simultaneously. I would like to implement the same feature in my own application and I have given this a bit of t...

Is there a fast way to change all the collation to utf8_unicode?

I have realised after making about 20 tables that I need to user utf8_unicode as opposed to utf8_general. What is the fastest way to change it using PHPMyAdmin? I had one idea: Export the database as SQL then using notepad run a find and replace on it and then reimport it... but it sounds like a bit of a headache. Is there a better way...