mysql

How can I implement an "interesting tags" feature like that on Stack Overflow?

Check my other question with bounty: http://stackoverflow.com/questions/3436287/finding-similar-number-patterns-in-table I'm trying to implement an Interesting Tags feature. For reference, this is how it works on SO: I add into the "interesting" list my interested tags (like php, mysql, jquery and so on). Then, if any of the display...

Faster way to know the total number of rows in MySQL database?

If I need to know the total number of rows in a table of database I do something like this: $query = "SELECT * FROM tablename WHERE link='1';"; $result = mysql_query($query); $count = mysql_num_rows($result); Updated: I made a mistake, above is my actual way. I apologize to all So you see the total number of data is recovered scannin...

Prepared Statements in MySql 5.1

This one is really puzzling. I can't seem to be able to run any prepared statement on MySql 5.1. Any simple select I'm writing runs fine but when I'm trying to run it from a prepared statement I'm getting Query returned no result set. What Am I doing wrong? Exmaple: prepare s from 'select * from t'; execute s; Thanks! ...

Can I use foreign key restrictions to return meaningful UI errors with PHP

I want to start by saying that I am a big fan of using foreign keys and have a tendency to use them even on small projects to keep my database from being filled with orphaned data. On larger projects I end up with gobs of keys which end up covering upwards of 8 - 10 layers of data. I want to know if anyone could suggest a graceful way ...

Rails: Display Maintenance Page if No Database Connection Available

I'm looking for a solution that will allow my rails app to render a user-friendly maintenance page when there is no Mysql server available to connect to. Normally a Mysql::Error is thrown from the mysql connection adapter in active_record. Something like: /!\ FAILSAFE /!\ Wed May 26 11:40:14 -0700 2010 Status: 500 Internal Server Err...

Sync tables between different database providers

I have 2 tables in 2 different databases, one is in a mysql server and one is in an informix server. Using .net and odbc, is there a way to identify the differences of both tables and merge them? so that both informix database and mysql database have the same data. thanks. ...

Macports compile of MySQL++ failing.

Before running "sudo port install mysqlxx +universal", I installed the universal variant of mysql5. ... checking whether -lm is needed to use C math functions... no checking whether -lsocket is needed... no checking whether -lnsl is needed... no checking for MySQL library directory... /opt/local/lib/mysql5/mysql checking for MySQL i...

MySQL text field issues

This is quite a noobish question, I have searched for a few hours now and I know this has to be simple. I am using XAMPP and I am trying to learn some more about using PHP and mySQL together. When I create the DB and the table for information to store, I tried insert info to the table and it stores it as a .dat file rather than text. I k...

Need help INSERT record(s) MySQL DB

I have an online form which collects member(s) information and stores it into a very long MySQL database. We allow up to 16 members to enroll at a single time and originally structured the DB to allow such. For example: If 1 Member enrolls, his personal information (first name, last name, address, phone, email) are stored on a single r...

mysql: difference between primary key and unique index?

Possible Duplicates: What is the difference between a primary key and a unique constraint? Primary key or Unique index? i need to change one of the fields of a table to auto increment and to be the primary key. what does unique index mean? ...

how do i select the last 10 records added?

i am running mysql and i would like to display the last 10 records that were added. what is the select statement for this? ...

PHP/mysqli: Inserting IP address with mysqli_stmt_bind_param()

Hello! I have a database table which contains an unsigned integer field to store the visitor's IP address: `user_ip` INT(10) UNSIGNED DEFAULT NULL, Here's the snippet of PHP code which tries to store the IP address: $ipaddr = $_SERVER['REMOTE_ADDR']; if ($stmt = mysqli_prepare($dbconn, 'INSERT INTO visitors(user_email, user_ip) VALU...

learning to make sense of the syntax of syntax

i want to use alter table but the syntax posted here: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html is very confusing i do not understand what the [ ] mean or the { } mean or the pipes is there some kind of tutorial that can help me understand this? ...

Regular Expression to parse SQL Structure

I am trying to parse the MySQL data types returned by "DESCRIBE [TABLE]". It returns strings like: int(11) float varchar(200) int(11) unsigned float(6,2) I've tried to do the job using regular expressions but it's not working. PHP CODE: $string = "int(11) numeric";<br/> $regex = '/(\w+)\s*(\w+)/';<br/> var_dump( preg_split($...

Getting deadlocks in MySQL

We're very frustratingly getting deadlocks in MySQL. It isn't because of exceeding a lock timeout as the deadlocks happen instantly when they do happen. Here's the SQL code that is executing on 2 separate threads (with 2 separate connections from the connection pool) that produces a deadlock: UPDATE Sequences SET Counter = LAST_INSERT...

MySQL: Ignore a selected column when using DISTINCT

Let's say: I want to query colA, colB and colC in my table. I want to see DISTINCT values but I don't want colA to be a criteria for distinction. Omitting colA isn't an option. What's the best way to structure that query? ...

fetching rows from mysql table and displaying them as JGROWL notifications

hey guys, i am having problems implementing my php/mysql code into a jgrowl if you are familiar with jgrowl you will know it delivers notifications like Growl does for OS X i am trying to get it read all the records from my table but at the moment it is only displaying one record as a notification and it loops through it 4 times ano...

mysql create table help with unique

I'm trying to create a table, and can't figure out how to assign two columns to be unique.. I know how to alter a table thats already created, but how do you do it in the create.. im after a create if not exist col1 TEXT, col2 TEXT, col3 TEXT unique(col1, col2) ^very rough basic but you get the idea ...

Select random line in SQL database

Hi, I would like to select a random line in my database. I saw this solution on a website: SELECT column FROM table ORDER BY RAND() LIMIT 1 This SQL query run but someone said me that it was a non performant query. Is there another solution ? Thx ...

MySQL query optimization - distinct, order by and limit

I am trying to optimize the following query: select distinct this_.id as y0_ from Rental this_ left outer join RentalRequest rentalrequ1_ on this_.id=rentalrequ1_.rental_id left outer join RentalSegment rentalsegm2_ on rentalrequ1_.id=rentalsegm2_.rentalRequest_id where this_.DTYPE='B' and this_.id<=1848978...