mysql

How to perform page control?

I mean what the most efficient way to get information about the quantity of your page's items and make sql query with LIMIT that you need. or I should get all items and then crop array with php functions? now I do 2 queries: first to count all items and second to get items that I need with LIMIT. OK, I'll be more concrete. For exam...

Remapping/Concatenating in SQL

I'm trying to reorder/group a set of results using SQL. I have a few fields (which for the example have been renamed to something a bit less specific), and each logical group of records has a field which remains constant - the address field. There are also fields which are present for each address, these are the same for every address. ...

Ajax "Is there new content? If so, update page" - How to do this without breaking the server?

It's a simple case of a javascript that continuously asks "are there yet?" Like a four year old on a car drive.. But, much like parents, if you do this too often or, with too many kids at once, the server will buckle under pressure.. How do you solve the issue of having a webpage that looks for new content in the order of every 5 second...

Which MySQL Datatype to use for storing boolean values from/to PHP?

Since MySQL doesn't seem to have any 'boolean' datatype, which datatype do you 'abuse' for storing true/false information in MySQL? Especially in the context of writing and reading from/to a PHP-Script. Over time I have used and seen several approaches: tinyint, varchar fields containing the values 0/1, varchar fields containing the...

Executing shell command from MySQL

I know what I'm looking for is probably a security hole, but since I managed to do it in Oracle and SQL Server, I'll give it a shot: I'm looking for a way to execute a shell command from a SQL script on MySQL. It is possible to create and use a new stored procedure if necessary. Notice: I'm not looking for the SYSTEM command which the ...

Alternative to "PDO::lastInsertId" / "mysql_insert_id"

I always hear that using "lastInsertId" (or mysql_insert_id() if you're not using PDO) is evil. In case of triggers it obviously is, because it could return something that's totally not the last ID that your INSERT created. $DB->exec("INSERT INTO example (column1) VALUES ('test')"); // Usually returns your newly created ID. // However w...

What is the difference between BIT and TINYINT in MySQL?

In which cases would you use which? Is there much of a difference? Which I typically used by persistence engines to store booleans? ...

ORM solutions for multi-database queries

In an ORM you can have nice syntax like this: my $results = Model.objects.all()[10]; And in the Django ORM it even quite nicely handles foreign key relationships and many to many relationships all through the ORM. However, in MySQL you can run a query like this: SELECT t1.column1 , t2.column2 , t3.column3 FROM db1.table...

Handling MySQL Full Text Special Characters

When using MySQL full text search in boolean mode there are certain characters like + and - that are used as operators. If I do a search for something like "C++" it interprets the + as an operator. What is the best practice for dealing with these special characters? The current method I am using is to convert all + characters in the dat...

Array slicing / group_concat limiting in MySQL

Let's say I have a table: i j --- a 1 a 2 a 3 a 4 b 5 b 6 b 7 b 8 b 9 Obvoiusly SELECT a, GROUP_CONCAT(b SEPARATOR ',') GROUP BY a would give me a 1,2,3,4 b 5,6,7,8,9 But what if I want to get only a LIMITED number of results, like 2, for example: a 1,2 b 5,6 Any ideas? ...

Tree library for PHP using left & right ids

I'm looking for a library in PHP that can create a tree structure from a database (or array of values) with left and right ids. For the result when getting values I am only looking for an array so I can create any type of view. For adding and removing, it would be nice if the library did it all. Even if the library is within another libr...

inserting hex value into mysql

Can there any way to insert a hex value into MYSQL? I also want to be able to retreive it in hex form. For example, something like: INSERT INTO table ( hexTag ) VALUES ( HEX(0x41) ); And if I do this, I want it to put an 'A' into the table ...

What would lead to an "Unknown object in backup file" problem when restoring a backup of a MySQL database?

Unfortunately, the problem is not more specific than that. I've found a few examples of people reporting similar problems by doing a Google search, but I can't find the part of the restore that is actually causing the problem, which might help me track it down on my own. Suggestions for either resolving this problem or being able to tra...

F# Beginner: retrieving an array of data from a server

I'm trying to grab data from a MySQL database. Approach 2 - apply/map style I'm using the MySQL ADO Reference to try to build this system. In particular, the example found at 21.2.3.1.7. (using a pseudo code) let table = build_sequence(query.read) Where query.read returns a row in the table(Or rather, a list of elements that happen...

Silent/No User Interaction modes for MySQL installation and Configuration Wizard?

I am implementing an installer for one of our products that requires MySQL as a prerequisite. I would like to have a bootstrap program that queries the user for any information needed for any prerequisite products and our product. Once the user has entered in all the necessary information they can press next and walk away while the ins...

MySQL inserting data only if table doesn't exist

Using strictly SQL (no PHP or anything else), is it possible to create a table and insert default data into that table only if that table doesn't exist? ...

Can I run an HTTP GET directly in SQL under MySQL?

I'd love to do this: UPDATE table SET blobCol = HTTPGET(urlCol) WHERE whatever LIMIT n; Is there code available to do this? I known this should be possible as the MySQL Docs include an example of adding a function that does a DNS lookup. MySQL / windows / Preferably without having to compile stuff, but I can. (If you haven't heard o...

How wrong is it to have a unique and normal index on the same column?

I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL auto_increment, `date_expired` datetime NOT NULL, `user_id` int(11) NOT NULL, `foreign_id` int(11) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `date_expired` (`date_expired`,`user_id`,`foreign_id`), KEY `user_id` (`user_id`) ) ENGINE=MyISAM DEF...

MySQL True vs False optimization

Can someone explain to me why I'm seeing the following behavior: mysql> show index from history_historyentry; +----------------------+------------+------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name ...

PHP MYSQL - Many data in one column

Hi, I need to store of 100-200 data in mysql, the data which would be separated by pipes.. any idea how to store it on mysql? should I use a single column or should I make many multiple columns? I don't know exactly how many data users will input. I made a form, it halted at the part where multiple data needs to be stored. Anyone kn...