mysql

PHP MySql Storing Data for 24 hours

I'm building a toplist for my site and instead of recording in and out hits and emptying the database every 24 hours I would like to record in and out hits "within the last 24 hours", this way the toplist will always look busy no matter what time you look at it, while still acurately ranking sites. So basically I'll have to add a recor...

XtraDB or InnoDb. Which to choose on a website with high concurrency of reads and writes.

We have MySQL 4 master masters and several read slaves of each master running MySQL. We roll with InnoDB, should we be looking towards XtraDB? We have to be able to average many comments a second which typically trigger 10 inserts and 100 reads. ...

MySQL - 'seeing' other rows

I have a query which produces a list of orders like this: Invoice Description Qty Amount VAT VAT code 3761 Flyers -1 -100 0 Z 3761 Business Cards -1 -75 -11.25 S 3761 Business Cards -1 -75 -11.25 S 3761 Discount(10%) -1 25 ...

how to connect and insert and retrieve data from database?

$con = mysql_connect("localhost","music123_sri","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("music123_telugu", $con); $sql="INSERT INTO xml (File) VALUES (" . mysql_escape_string($xmlString) . ")"; $data = mysql_query("SELECT File FROM xml") $info = mysql_fetch_array( $data ); can u...

Which is more efficient: Multiple MySQL tables or one large table?

I store various user details in my MySQL database. Originally it was set up in various tables meaning data is linked with UserIds and outputting via sometimes complicated calls to display and manipulate the data as required. Setting up a new system, it almost makes sense to combine all of these tables into one big table of related conten...

mysql left join, how to write such query?

I have first: select url from urls where site = '$value' order by url second: select id, widget_name from widgets where display_urls LIKE 'urls.url' and is_father=1 order by id Third: select id, widget_name from widgets where display_urls RLIKE 'urls.url' and is_father=0 order by id Fourth: select id, widget_name, father_widg...

join query returning odd results

I use this query to display a list of songs and show what songs have been clicked as a favorite by a user. $query = mysql_query( sprintf(" SELECT s.*, UNIX_TIMESTAMP(`date`) AS `date`, f.userid as favoritehash FROM songs s LEFT JOIN favorites f ON f.favorite = s.id AND f.user...

Is it possible to refactor this MySQL stored procedure loop?

Hi! I have a loop in MySQL stored procedure where i insert record almost for each iteration. Well known problem is that inserting row-by-row is inefficient and i'd rather see inserts with multiple value lists instead. Pseudo-example of current procedure: CREATE PROCEDURE p_foo_bar() BEGIN DECLARE foo VARCHAR(255); DECLARE my_cursor...

How to highlight changes/difference in one text paragraph from the other?

Hi! Is it possible to highlight the modifications in one text paragraph from the other? For example, there are 3 text fields in a database. Non-admin users can edit the text and submit for approval. When the admin logs in, (s)he can open the approvals page and it shows the original text and user submitted text with modifications. Usual...

MySQL FULLTEXT not working

I'm attempting to add searching support for my PHP web app using MySQL's FULLTEXT indexes. I created a test table (using the MyISAM type, with a single text field a) and entered some sample data. Now if I'm right the following query should return both those rows: SELECT * FROM test WHERE MATCH(a) AGAINST('databases') However it retur...

Deleting related records in MySQL

I have two MySQL (MyISAM) tables: Posts: PostID(primary key), post_text, post_date, etc. Comments: CommentID(primary key), comment_text, comment_date, etc. I want to delete all the comments in the "Comments" table belonging to a particular post, when the corresponding post record is deleted from the "Posts" table. I know this can ...

In SQL, how do I fetch a row with a specific column value if available, otherwise any other row

I currently have the following Product table: Product _______ id, INT name, String featured, ENUM(Y, N) If there is a featured product in the above, I will return that item. If none of the above are featured, I will return anyone of them. I currently have the following query which is functional: SELECT * FROM Product WHERE (featured...

Getting the ID's of all selected field in php

When i select multiple checkbox, i get the values something like this.... 9,[email protected],1,9,[email protected],2,2,[email protected],3,2,[email protected],4 Now i need to delete all of them, so i need to pass their user ID alone to query. For this i need to split the string and pass their multiple ID's alone to query. $var1 = $theArrayValu...

Debug MySQLs "too many connections"

I'm trying to debug an error I got on a production server. Sometimes MySQL gives up and my web app can't connect to the database (I'm getting the "too many connections" error). The server has a few thousand visitors a day and on the night I'm running a few cron jobs which sometimes does some heavy mysql work (Looping through 50 000 rows,...

Where and when to open a database connection

I am working on implementing use of the mysql class found here in an existing script. The script almost always needs to interact with the database, even if there are times when it does not. What is the best practice in this case? Should I open a connection and keep that open until the end of the script or should I open a connection when ...

Order by day_of_week in MySQL

How can I order the mysql result by varchar column that contains day of week name? Note that MONDAY should goes first, not SUNDAY. ...

MySQL LIKE IN() ?

My current query looks like this: SELECT * FROM fiberbox f WHERE f.fiberBox LIKE '%1740 %' OR f.fiberBox LIKE '%1938 %' OR f.fiberBox LIKE '%1940 %' I did some looking around and can't find anything similar to a LIKE IN() - I envision it working like this: SELECT * FROM fiberbox f WHERE f.fiberbox LIKE IN('%140 %', '%1938 %', '%1940 ...

Group_concat MySQL function's equivalent in Oracle

Hi i am looking for a function same group_concat of mysql in oracle or some functionality ...

Wordpress uses MySQL fulltext search?

Hello Stack Overflow. I have a PHP/MySQL installation. I'm working on a program that uses a MySQL Fulltext search. I want to reduce the min word length to three. I know I can do this by changing the ft_min_word_length global variable and restarting MySQL. My problem is that the MySQL server is running several other databases, including...

Jboss unable to open DB connections to mySql

We are having repeated failures of our Application running on Jbos 4.05, mysql 5.083. Server works great for about 6 hours using no more then 10 connections to the mysql. Then suddenly get errors like:b. Looks like server attempts to open more connections, mysql connection peak at about 150 and then the server just hangs and looks like a...