mysql-query

fetch_all or fetch_assoc MySQLi statement

Hi, is it possible to use the fetch_all(), fetch_assoc() etc. from the the MySQLi_Result class with a prepared statement from the MySQLi_STMT class? I've done it using the query() method in the Mysqli class (and by escaping trough mysqli_real_escape_string()), but not using statements with binding parameters. I'm considering using PDO ...

Optimize this MySQL query?

The following query takes FOREVER to execute (30+ hrs on a Macbook w/4gig ram) - I'm looking for ways to make it run more efficiently. Any thoughts are appreciated! CREATE TABLE fc AS SELECT threadid, title, body, date, userlogin FROM f WHERE pid NOT IN (SELECT pid FROM ft) ORDER BY date; (table "f" is ~1 Gig ...

MySQL function: Rotate old entries to archive table

Hi, I'm looking for the function that will take rows older then X days and put it in archive table... Was thinking to make function so it will be easer to execute... something like CREATE TABLE archive_NUMBER_OF_WEEK (...); INSERT INTO archive_NUMBER_OF_WEEK SELECT * FROM content WHERE DATE < X days; DELETE * FROM content WHERE DATE < ...

How to select domain name from email address

I have a email address like [email protected] and [email protected] [email protected] ... etc I want a Mysql select query so that it would trim user names and .com an returns output as gmail,ymail,hotmail etc ...

SQL Query about blob length

Is there a way to query a MySQL database that gives me all blobs that are bigger than 1kb? ...

MySQL query for initial filling of order column

Sorry for vague question title. I've got a table containing huge list of, say, products, belonging to different categories. There's a foreign key column indicating which category that particular product belongs to. I.e. in "bananas" row category might be 3 which indicates "fruits". Now I added additional column "order" which is for dis...

MySQL inner join problem or other equal solution

Hello, For a few hours I was figuring out how to make an inner join these tables(tables are simplified for this question): Table message have these fields: | id | content | Table message_relation have these fields: | id | message_id | sender_id | receiver_id | Table user have these fields: | id | name | What I want to do with th...

Variables are "lost" somewhere, then reappear... all with no error thrown.

Hi All, I'm probably going to make myself look like a fool with my horrible scripting but here we go. I have a form that I am collecting a bunch of checkbox info from using a binary method. ON/SET=1 !ISSET=0 Anyway, all seems to be going as planned except for the query bit. When I run the script, it runs through and throws no erro...

Remove everything before first # in mysql field

Excuse my ignorance. I need to replace all data in a mysql field before and including the first # . example field = golfers data at the first hole the golfer missed a 9 inch putt and said "#hit it bad new data hit it bad ...

Preview result of update/insert query without comitting changes to database in MySQL?

I am writing a script to import CSV files into existing tables within my database. I decided to do the insert/update operations myself using PHP and INSERT/UPDATE statements, and not use MySQL's LOAD INFILE command, I have good reasons for this. What I would like to do is emulate the insert/update operations and display the results to t...

Print results of a SELECT query as preformatted text in PHP?

I'm looking for an easy and quick way to print out the results of a MySQL SELECT query in PHP as preformatted text. What I would like is to be able to pass a query object to a function and get a printout of the recordset like the command line MySQL client does when running SELECT statements. Here is an example of how I want it to look ...

Query Months help

Hey all i am in need of some helpful tips/advice on how to go about my problem. I have a database that houses a "signup" table. The date for this table is formated as such: 2010-04-03 00:00:00 Now suppose i have 10 records in this database: 2010-04-03 00:00:00 2010-01-01 00:00:00 2010-06-22 00:00:00 2010-02-08 00:00:00 2010-02-05 00:...

What are maintenance steps and performance steps for Mysql server/database ?

Like index maintenance we have index reorganize/rebuild, update stats, shrink database log files , database backup/restore in MS SQL server, What are maintenance steps and performance steps for Mysql server/database ? ...

MYSQL: Error: Cannot add or update a child row: a foreign key constraint fails

Hi all, Using MySQL on Windows OS, and am getting an error upon attempting to create a foreign key between two tables: CREATE TABLE tf_traffic_stats ( domain_name char(100) NOT NULL, session_count int(11) NULL, search_count int(11) NULL, click_count int(11) NULL, revenue float NULL, rpm float NULL, c...

Improve long mysql query

I have a php mysql query like this $query = <<<EOS SELECT * FROM articles FORCE INDEX (articleindex) WHERE category='$thiscat' AND did>'$thisdid' AND mid!='$thismid' AND status='1' AND group='$thisgroup' AND pid>'$thispid' LIMIT 10 EOS; As optimization, I've indexed all the parameters in arti...

MySQL 5 in MySQL 4 compatible mode for one database?

In a recent project, I have to maintain some PHP code. I set up a development server and installed MySQL, Apache, PHP, ..etc. The program is terminated with an error: Unknown column _ _ _ in 'on clause' Cannot select .... Google shows that it's a change of syntax around JOINs, parentheses are needed. As you may imagine, fixing all ...

Improve long mysql query

I have a php mysql query like this $query = "SELECT * FROM articles FORCE INDEX (articleindex) WHERE category='$thiscat' and did>'$thisdid' and mid!='$thismid' and status='1' and group='$thisgroup' and pid>'$thispid' LIMIT 10"; As optimization, I've indexed all the parameters in articleindex and I use force index to force mysql to use...

How do I apply a string function to a table column?

As part of a query result, a column with names is returned. I want to apply a function so that the order of first and last name is flipped in my $db results. What is the most efficient way to accomplish this? There answer probably lies in using either the foreach function, array_walk or array_map but I don't know the proper syntax. ...

Is mysql_query under PHP a blocking function?

Suppose I am executing several queries on the server using mysql_query. The results of every query affect the subsequent query. Will every call of mysql_query be completely executed before control moves on to the next one? Edit: I forgot to mention, I am not using a transactional storage engine. ...

I need to calculate the date / time difference between one date time column

Details. I have the notes table having the following columns. ID - INT(3) Date - DateTime Note - VARCHAR(100) Tile - Varchar(100) UserName - Varchar(100) Now this table will be having NOTES along with the Titles entered by UserName on the specified date / time. I need to calculate the DateTimeDifference between t...