mysql

How to validate drop down menus in php??

Its like we have to insert the Date of Birth(which is a drop down box containing DD/MM/YYYY) in MySql by validating it..How can it be done? Thanks for the help. ...

How to edit values in a returned mysql result resource and forward edited result resource

Here's what I'm trying to do ... Im using Flash to call an AMFPHP service that queries my database and returns the result resource. Before returning the result to the Flash movie I need to edit some of the values in the result resource. How can i iterate through the rows of the result, change some values and 'repackage' the resource t...

MySQL trigger : is it possible to delete rows if table become too large ?

Hi, When inserting a new row in a table T, I would like to check if the table is larger than a certain threshold, and if it is the case delete the oldest record (creating some kind of FIFO in the end). I thought I could simply make a trigger, but apparently MySQL doesn't allow the modification of the table on which we are actually inse...

MySQL and Check Constraints

I have inherited an application that uses MySQL and that is used by a PHP front end. The guy that wrote this system has gone to some fairly convoluted lengths to ensure that codes that users enter are valid - and tat means that these codes also exist in another table. When I first saw this I wondered why he hadn't used CHECK constraints...

Understanding Plesk Watchdog statistics

We have Plesk 8.3 installed. I've started using their Watchdog module to track server useage. Our server routinely has trouble with the amount of traffic we have and I think our MySQL queries need to be smarter. Anyway, looking at the stats from Watchdog, it seems like MySQL usage is low compared to so something else making up the "ov...

How do I get dbunit to play nice with MySQL enum data types?

I'm trying to use dbunit to test some our database access code and I'm running into a problem. We are using MySQL 5 something or other as the database itself. I exported a small set of data to a FlatXmlDataSet and when I setup the test case, it throws an exception which says "Data truncated for column 'FHEIGHT_FLAG' at row 1". The colu...

How do you safely and efficiently get the row id after an insert with mysql using MySQLdb in python?

I have a simple table in mysql with the following fields: id -- Primary key, int, autoincrement name -- varchar(50) description -- varchar(256) Using MySQLdb, a python module, I want to insert a name and description into the table, and get back the id. In pseudocode: db = MySQLdb.connection(...) queryString = "INSERT into tablenam...

Fastest way to format SQL results in PHP

What's the fastest (best performing) way in PHP to transform a (My)SQL result like: array( array('user_name' => 'john', 'tag_id' => 1, 'tag_name' => 'foo'), array('user_name' => 'john', 'tag_id' => 2, 'tag_name' => 'bar'), array('user_name' => 'rick', 'tag_id' => 3, 'tag_name' => 'foobar'), array('user_name' => 'rick', 'tag_id' => 2...

redirect user, then log his visit using php and mysql

I have a PHP redirect page to track clicks on links. Basically it does: - get url from $_GET - connect to database - create row for url, or update with 1 hit if it exists - redirect browser to url using Location: header I was wondering if it's possible to send the redirect to the client first, so it can get on with it's job, and t...

How do I select rows from a MySQL table grouped by one column with required values in another

I need to filter products where certain attributes are stored in a joined table that match all the required properties, i.e. users need to be able to gradually narrow down their search by adding requirements. The problem really just concerns the properties table I think, rather than the join, given the following (simplified) table of p...

How to prevent, counter or compensate for, an empty/NULL field (MySQL) returning an empty set...

I'm learning PHP and MySQL to get a hang of server-side scripting and for personal interest/development. The first 'program,' beyond 'hello world' seems to be writing ones' own blog. This is a little beyond me yet and so thought I'd start with a contacts-database type. So far so good, but (and there's always the but!) I'm trying to form...

How do you output MySQL query results in csv format (to the screen, not to a file)?

I'm trying to output query results in comma delimited format using the mysql command line tool. My mysql user does not have access to use the "INTO OUTFILE" option referenced in this question: http://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format I'm also aware of the -H and -X options to format ou...

"Cannot convert to a SELECT statement" What does this mean

I'm trying to make our mySQL database run faster and I've analyzed our slow query log and the most common slow query is this: CREATE TABLE IF NOT EXISTS `wp_bad_behavior` ( `id` INT(11) NOT NULL auto_increment, `ip` TEXT NOT NULL, `date` DATETIME NOT NULL default '0000-00-00 00:00:00', `request_method` TEXT NOT NULL, `request_uri` ...

Add date/time to MySQL table?

How can I add the current date and time (the date and time set on the server) to a MySQL table? ...

Automated E-mail with PHP and MySQL?

How can I send an automated e-mail to a users entered e-mail address? I have Xampp, which is a local web server equipped with Apache, and Mercury for mail. Ideas? ...

Why do the results of this MySQL query get multiplied by each other?

SELECT user_id, SUM(COALESCE(point_points, 0)) AS total_points, SUM( CASE WHEN point_date > '$this_month' THEN point_points ELSE 0 END) AS month_points, COUNT(DISTINCT c_id) AS num_comments, COUNT(DISTINCT rant_id) AS live_submissions FROM users LEF...

Remove Orphaned Items In A Hierarchy

I have a list of items in MySQL, connected through a column "parent_id". Let's assume the columns are: id, name, parent_id If one of my users deletes an item high in the hierarchy, I need to delete all of its children. So, two part question: 1) Is there an effective and efficient MySQL call that will return ID's for all items where ...

Differences between index, primary, unique, fulltext? MySQL

What are the differences between primary, unique, index and fulltext when creating MySQL tables? How would I use them? ...

Please teach it about mysql_pconnect.

I read specifications of mysql_pconnect of the function of PHP.. "mysql_pconnect is that connection with the SQL server is not closed even if the practice of the script is finished". There is it unless connection is closed, but will it be that connection stays until a timing of the reboot of mysql? ...

Simple select nth highest

I'm trying to figure out which is the more efficient way to get the nth highest record in a mySQL database: SELECT * FROM table_name ORDER BY column_name DESC LIMIT n - 1, 1 or SELECT * FROM table_name AS a WHERE n - 1 = ( SELECT COUNT(primary_key_column) FROM products b WHERE b.column_name > a. column_name) There ...