mysql

Getting row before and after a query

I currently have this query SELECT short_url, type, file_thumbnail, file_embed, media.id, user, media.file_url, votes, comments, GROUP_CONCAT(info.itemTime) AS time, info.title, media.time AS oldTime, media.title, info.topic, ...

If an PHP PDO transaction fails, must I rollback() explicitely?

I've seen an code example where someone does a $dbh->rollback(); when there occurs an PDOException. I thought the database will rollback automatically in such a case? ...

MYSQL syntax error 1064

I just cant figure out why am getting error 1064 from this query //prep the data for database use $manufacturer_id = $_GET['id']; $manufacturer_display_name = mysql_prep($_POST['manufacturer_display_name']); $manufacturer_name = mysql_prep($_POST['manufacturer_name']); $query = "UPDATE IT_manufacturer SET manufacturer_name = '...

How to Use Mathematic Equations as Filters in SQLAlchemy

I'm using the SQLAlchemy ORM to construct the MySQL queries in my application, and am perfectly able to add basic filters to the query, like so: query = meta.Session.query(User).filter(User.user_id==1) Which gives me something basically equivalent to this: SELECT * FROM users WHERE user_id = 1 My question is how I would integrate s...

Objects in PHP: More or Less is better?

I have asked aqbout timezones and date/time before but this is a more specific question, more about Objects in PHP. <?PHP //set the user's time zone on page load date_default_timezone_set("America/Los_Angeles"); //convert the timestamp from DB into the user's time $timestamp = '2008-05-01 13:44:19'; //this would normally be returned ...

Coerce result row into object

Is there a way to coerce the result row gotten from calling a stored procedure into a specific object so I can pass just a list of that object into the view? I know I can use things like Node.list() to do this, but I am eventually going to replace getnodes() with a fairly complicated stored procedure that creates temp tables and does so...

Is it better to use mysql or files to store data?

I'm wondering if it's better to use mysql or use files to store data? What is safer, what is faster? I'm talking about php and mysql. ...

Error When creating a foriegn key

Hello, I'm getting this error when trying to add a foreign key contraint: #1005 - Can't create table './testtable/#sql-595_146.frm' (errno: 150) I need to do an ON DELETE CASCADE for all images that share a project id when that project is deleted. My simplified table structure is as follows: CREATE TABLE IF NOT EXISTS `images` ( `im...

Open MySQL slow query log with PHP

I'm having trouble opening MySQL's slow query log with PHP. I'm writing a debugger and trying to tap into the log file but it's giving me a permission denied message. Code: $log = file_get_contents('/var/log/mysql/mysql-slow.log'); Response (error): Warning: file_get_contents(...): failed to open stream: Permission denied ... I ca...

What are differences between INSERT and UPDATE in MySQL?

It seems INSERT and UPDATE do the same things to me. Is there any occasions where I should use INSERT instead of UPDATE and vice versa? ...

Need advice on how to save all stock changes for rpg game in mysql.

I've been creating rpg game and now I'm doing stock-market for my players that they could buy and sell shares. Stock prices are random and stock prices changes every 20 minutes. So, every change I have to save in mysql in one field because I want to show players graph of last month's changes. For example. first stock price is 100$, then,...

PHP checking entries in array for duplicates

I want to take all the records from my MySQL table and check if there are duplicates. I had the idea of storing them all in an array and then checking the array for duplicates. The problem is, I have about 1.5 million rows in my MySQL table. This is my code so far: <?php $con = mysql_connect('localhost', 'root', ''); $sel = mysql_sele...

[SOLVED]Mysql optimization

Here you have a screenshot from my table structure:http://img64.imageshack.us/img64/54/pictx.jpg On my site I have two fields for the search, one for the city(ort) and one for industry(branche), and if I search for: Frankfurt verschierung, let's say that in the field for city I have: Frankfurt and in the field for industry(branche) I ha...

MySQL - Conditional Foreign Key Constraints

Hi there, I have following 'comments' table in my app: comments -------- id INT foreign_id INT model TEXT comment_text TEXT ... the idea of this table is to store comments for various parts of my app - it can store comments for blog post i.e: 1|34|blogpost|lorem ipsum... user picture: 2|12|picture|lorem ipsum.....

Should I use indexes for a many-to-many database table?

Hi there, does it make sense to create indexes for a table called user_movies with the following columns: user_id movie_id There will be much more reading than inserting or updating on this table but I'm not sure what to do. Also: Is it adequate to omit a primary key in this situation? ...

Considerations for very large SQL tables?

I'm building, basically, an ad server. This is a personal project that I'm trying to impress my boss with, and I'd love any form of feedback about my design. I've already implemented most of what I describe below, but it's never too late to refactor :) This is a service that delivers banner ads (http://myserver.com/banner.jpg links to h...

MySQL: Is there a way to update an entire table in one query?

Hey Everyone, I need to update all the records of a table(shouldn't be over a 100 records). Each record will need to have a field updated with a different value. Am I going to have to make a query for each update or is there another way? I can't seem to figure out to do it at once Thanks for the help! EDIT: To clarify, each field tha...

Rails app reports crazy 'DB' times, or is maybe hung up in the mysql layer?

At some point in the past week, my production logs began showing bizarre numbers that don't ad up, like: Completed in 52ms (View: 26, DB: 1129) This query did take over one second. But, there was no database activity - no sql queries shown in mysql log nor rails log. So, somehow the Rails app is spending a tremendous amount of time d...

Basic PHP MySQL array grouping question

Quick question, which I think has a very easy solution for someone who has anything above the most rudimentary knowledge of PHP/MySQL as I do. I have a list of cities in a variety of states stored in a database with city, state and some other variables. Right now they get pulled as a list sorted by city name: Anchorage, AK Baltimore, ...

What differences do I have to take into account if using MySQL Transactions?

I was recently told that I should use transactions in my application as they can help run code quicker and prevent MySQL code from executing before a whole page has loaded (e.g. if someone is just refreshing on my page and the whole page doesn't load, no MySQL calls will start and it reduces load on the server.) I'm wondering if I wante...