mysql

Possible to use multiple/nested MySQLi statements?

Is it possible to have a MySQLi prepared statement within the fetch() call of a previous statement? If not, what's the best way around it? Example code: if($stmt = $link->prepare("SELECT item FROM data WHERE id = ?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($item); while( $stmt->fetch() ) { /* ...

What MySQL client application would you recommend for Mac OS X?

My colleagues and I are looking for alternative client tools for Mac OS X. I tend to prefer the text-based interface and we have PHPMyAdmin installed on our development servers (Linux). What are your recommendations? (One recommendation per answer please, so people can up-mod individual recommendations). ...

Monthly Birthday SQL Query.

How would retrieve all customer's birthdays for a given month in SQL? What about MySQL? I was thinking of using the following with SQL server. select c.name from cust c where datename(m,c.birthdate) = datename(m,@suppliedDate) order by c.name ...

Why is ENUM better then INT

I just ran a "PROCEDURE ANALYSE ( )" on one of my tables. And I have this column that is of type INT and it only ever contains values from 0 to 12 (category IDs). And MySQL said that I would be better of with a ENUM('0','1','2',...,'12'). This category's are basically static and won't change in the future, but if they do I can just alter...

MySQL foreign keys - how to enforce one-to-one across tables?

If I have a table in MySQL which represents a base class, and I have a bunch of tables which represent the fields in the derived classes, each of which refers back to the base table with a foreign key, is there any way to get MySQL to enforce the one-to-one relationship between the derived table and the base table, or does this have to b...

Free supportticket software

I am searching for a better alternative to osTicket. Can you give any advise? [Update] I would want it not to be overfilled with features, since I want to be able to use it without having to get into it alot ...

Optimize SQL query on large-ish table

First of all, this question regards MySQL 3.23.58, so be advised. I have 2 tables with the following definition: Table A: id INT (primary), customer_id INT, offlineid INT Table B: id INT (primary), name VARCHAR(255) Now, table A contains in the range of 65k+ records, while table B contains ~40 records. In addition to the 2 primary k...

How do I convert between time formats?

I am looking to convert a mysql timestamp to a epoch time in seconds using php, and vice versa. What's the cleanest way to do this? ...

MySQL InnoDB database restore

I have to restore a database that has been inadvertently DROPped in MySQL 5.0. From checking the backup files, I only seem to have .FRM files to hold the database data. Can anyone advise whether this is all I need to perform a database restore/import from the backup, or are there other files I should have to hand to complete this? ...

Convert mysql timestamp to epoch time in python

Convert mysql timestamp to epoch time in python - is there an easy way to do this? ...

mysql replication with lots of temporary table writes

I've got a database which I intend to replicate for backup reasons (performance is not a problem at the moment). We've set up the replication correctly and tested it and all was fine. Then we realized that it replicates all the writes to the temporary tables, which in effect meant that replication of one day's worth of data took almos...

How can my application benefit from temporary tables?

I've been reading a little about temporary tables in MySQL but I'm an admitted newbie when it comes to databases in general and MySQL in particular. I've looked at some examples and the MySQL documentation on how to create a temporary table, but I'm trying to determine just how temporary tables might benefit my applications and I guess ...

Whats the best way to get total # of records in a mysql table with php?

Whats the most efficient way of selecting total number of records from a large table? Currently, Im simply doing $result = mysql_query("SELECT id FROM table"); $total = mysql_num_rows($result) I was told this was not very efficient or fast, if you have a lot of records in the table. ...

Loading an existing database into WWW SQL Designer?

I've used WWW SQL Designer several times to design databases for applications. I'm now in charge of working on an application with a lot of tables (100+ mysql tables) and I would love to be able to look at the relations between tables in a manner similar to what WWW SQL Designer provides. It seems that it comes with the provisions to hoo...

Best practices for withstanding launch day traffic burst

We are working on a website for a client that (for once) is expected to get a fair amount of traffic on day one. There are press releases, people are blogging about it, etc. I am a little concerned that we're going to fall flat on our face on day one. What are the main things you would look at to ensure (in advance without real traffic d...

What's the most efficient way to select the last n rows in a table without changing the table's structure?

What's the most efficient way to select the last n number of rows in a table using mySQL? The table contains millions of rows, and at any given time I don't know how large the table is (it is constantly growing). The table does have a column that is automatically incremented and used as a unique identifier for each row. ...

Tips on helping to move to MS SQL from MySQL

I have been interested in database developing for some time now and decided that MS SQL has a lot to offer in terms of T-SQL and generally much more functionality (not saying that Oracle or Postgres don't have that). I would like to know: What are the big paradigm changes I should expect to see? How much effort do "regular" compani...

Selecting values grouped to a specific identifer

I have an application that tracks high scores in a game. I have a user_scores table that maps a user_id to a score. I need to return the 5 highest scores, but only 1 high score for any specific user. So if user X has the 5 highest scores on a purely numerical basis, I simply return the highest one and then the next 4 user scores. I ...

MySQL Query: Select most-recent items with a twist

(Sorry the title isn't more help. I have a database of media-file URLs that came from two sources: RSS feeds and manual entries. I want to find the ten most-recently added URLs, but a maximum of one from any feed. To simplify, table 'urls' has columns 'url, feed_id, timestamp'. feed_id='' for any URL that was entered manually. How would ...

Stored Procedures, mySQL and PHP5

The question is a fairly open one. I've been using Stored Procs with MS SQLServer for some time with classic ASP and ASP.net and love them, lots. I do have a small amount of experience with PHP4 and mySQL, and previously when working with these was limited to in-line SQL. I have a small hobby project I'm working on and for various rea...