mysql

How do I create a default value for attributes in Rails activerecord's model?

Hi all, I want to create a default value for an attribute by defining it in ActiveRecord. By default everytime the record is created, I want to have a default value for attribute :status. I tried to do this: class Task < ActiveRecord::Base def status=(status) status = 'P' write_attribute(:status, status) end end But upon ...

Tools and Methods

What tools and procedures would you recommend or use yourself to help streamline the following sceanario: (I know its a long one but any help is appreciated) I work in a team that have an ecommerce app that we develop at our company. Its a reasonably standard LAMP application that we have been developing on and off for about 3 years. We...

Rails update_attribute did not hit the mysql database

It only happens in production, when we update some of the records through browser, the change was not saved. it does not seem to be a cache problem as we verified that the data in mysql was still the old data. However, the controller did get hit and flash message returned as if the change was made successfully. However, we can make the...

php mysql db connect very slow

I have a small PHP framework that basically just loads a controller and a view. An empty page loads in about 0.004 seconds, using microtime() at the beginning and end of execution. Here's the "problem". If I do the following: $link = @mysql_connect($server,$user,$pass,$link); @mysql_select_db($database, $link); the page loads in about...

Modifying an SQL query to exclude particular dates

Hey everyone, I have a pretty long SQL query that I use to, for all of the users in a particular "region", for a given month, calculate the number of days that they have been on "duty". This is broken down into weekends and weekdays. Here is the php/SQL statement: $result = mysql_query(" SELECT fname, lname, MONTH( eventDate ) AS MO...

MySQL - Connection using Singleton pattern or a ConnectionPool?

The topic has already been on the table in some previous questions. New elements come with new problems. I am seeking here for the best way to handle database connection(s), concerning aspects of : maintainability, performance, security and implementation. I must mention that i am not interested in abstractions like Hibernate, Spring, et...

Modify rows to increment in MySQL

I have the following table: http://kimag.es/share/59074317.png columns = [id cid comment] I need a way to make the values of cid (comment id) increase by 1 for every row in the table. row 1, cid=0 row 2, cid=1 row 3, cid=2 etc. Now cid=id because of this php script: <?php $con = mysql_connect("localhost","MYUSER","MYPASS"); if ...

what is better to use php query set or mysql function?

If you had data in table 1 that you need to use to return data in table 2 for each row returned in table 1. What is more efficient to use a set of querys in PHP one inbedded in the while loop of the other or an SQL function within a query? for example: $qry = mysql_query(SELECT date FROM table1) while($res = mysql_fetch_array($qry)) {...

MySQL view with a function to create an input variable.

Is it possible to create an SQL view in MySQL that takes an input variable say as a function argument? I have found this caption from the MySQL web site but am not sure how to use it as I am quite new to SQL functions. When I run this in the MySQL command prompt ,it gives me errors. Also I am not sure if this is even what I am looking f...

MySQL function which takes a set of strings?

There's a mysql function which works like this: SELECT * FROM myTbl WHERE name ???('bob', 'jane', 'sally') The above query should return all records where name is bob, jane, or sally. Where it says ??? above is where the function name should be. Can anyone remind me what that function is called? ...

Efficient MySQL query to find entries in A where not matched in B

I have a couple of tables (products and suppliers) and want to find out which items are no longer listed in the suppliers table. Table uc_products has the products. Table uc_supplier_csv has supplier stocks. uc_products.model joins against uc_suppliers.sku. I am seeing very long queries when trying to identify the stock in the products...

Problems loading bulk data in mysql using php.

I have a script that gets the raw binary image data via url request. It then takes the data and puts it into mysql. Pretty simple right? Well It's I'm inserting some 8,000 decent sized 600x400 jpegs and for some odd reason some of the images are getting cut off. Maybe the part of my script that iterates through each image it needs to ge...

Differentiate between columns In MySQL using PHP

If i have this Query: SELECT tableA.Id, tableB.Id FROM tableA JOIN tableB ON (tableA.bId = tableB.Id) Now if i try this in php i have some problems: while($result = mysql_fetch_array(mysql_query(/Query Above/)){ print $result['tableB.Id']; } Now i know what you are going to say that i should do my query as: SELECT tableA.Id AS...

php function to return sql results that contain arrays, as an array

So im having a problem (obviously). I have the following MySQL table data 7 USER1 1,1,1,10,1 The Guys Team 8,7,13,14,16 8 USER1 1,1,1,10,1 The Girls Team 7,12,15 10 USER1 1,1,1,10,1 Dog Team 8,7,14,15 I wrote a function to retrieve the data, and return it. function ShowSetTeams($coach){ $result = mysql_query("...

store and query xml data in MySQL

what are the good options to store xml structured data and query the data in MySQL? I know from mysql5.1.5 there is a function ExtractValue() to query the data directly, but due to certain limitations I can only use mysql5.0.x. what I need is to store the data in simple xml format, such as <person> <name>My Name</name> <gender>male</ge...

Transaction Processing Using PHP and MySQL

Hi, I'm trying to implement two-phase commit using PHP and MySQL, and coming up short. The main block I've found is that I'm unable to store the MySQL connection resource in a place where I can find it again for the second phase. Is it possible to serialize a database handle? Here's the case I'm trying to code for: User sends data Se...

MySQL Inner Query with a Where and Group by conditions in cakephp

Hi, i am having a table named Reports with id report_id user_id 1 1 5 2 1 5 3 1 5 4 2 5 5 2 5 6 3 6 7 3 6 8 4 1 9 4 1 10 4 1 i am trying to write a Query such that user_id = 5 and to find how many reports he has ...

How to optimize this SQL query?

I have a database with questions and answers that get translated into all languages that site is used by. But when a question is not translated yet I want to show that question in english language. So a gettext-like behavior. My current SQL query for this looks like this: SELECT * FROM questions_view WHERE `language` = "de" AND `#paren...

MySQL-SSL Configuration on Windows Machine ( openSSl, Mysql 5.1, IIS 5.0)

how to setup openssl at the mysql? "have_ssl" disabled; how to enable it? " mysql> SHOW VARIABLES LIKE 'have_ssl'; If the value is YES, the server supports SSL connections. If the value is DISABLED, the server supports SSL connections but was not started with the appropriate --ssl-xxx options" there is not very clear. how to enable i...

monthly breakdown of table data, date stored as epoch time

I have a mysql table that contains a date field in epoch time format. I need to count how many rows I have for each calendar month of the year. I don't even know where to start. Thanks in advance. ...