Tag: mysql
Another Freak Query
by Abu Aisyah on Oct.23, 2009, under Catatanku, Ngoprek
Yes true, I’m facing a crazy query once again. Actually, I could have done with a PHP script, but it did not really help me if I need dynamic data in the database. While I knew I could not work 100% in PHP scripts.
“TRUE POINT … +125 blåa blåa blaaa … … PIN = 34,234″
For the record, I just need a “TRUE POINT +125″, with the assumption that the number 125 is dynamic, such as 100, 10, 12,314, 7,723,423, and so on.
So I was really dizzy for 15 minutes
to look for. And finally I found a way, though I think I know there are other ways. But please know my friend, this is what I can and I find.
FROM tabel_string;
Once out of here I can know that there is a gap between the numbers and says thereafter. Quite right, space. That way I’ll be able to remove the value of the space, by looking for numbers in which the first space in the Instr. After that stay I love the functions left to cut it to only display + number only. : D
Then I just add concat function. Et voila, success. CMIIW.
Query in Mysql
by Abu Aisyah on Oct.15, 2009, under Catatanku, Ngoprek
I just found something, but perhaps already published on the web or in blogs on the internet. It turned out that mysql has a unique behavior for the query. And let us not carelessly in doing query command.
If we query the table which we have had millions of rows, then of course what we do should have to be careful. Computer resources can be exhausted due to our queries, so to run another process that will be felt slowly and I mean berat.Query also not query the ribet, fairly query like this.
“SELECT * FROM TABLE WHERE 1 AND CONDITION AND CONDITION AND CONDITION”.
The assumption is that we have a table where the line very much. Or maybe we’re using Query Join.
“SELECT * FROM TABLE A LEFT JOIN B ON A. TABLEB FIELD = B. FIELD WHERE 1 AND CONDITION AND CONDITION AND CONDITION”
I found it astonishing. Use WHERE number 1 after it has meaning. Number 1 in a query on the entire intention is to display the existing row in the table, and then carry out further conditions. As a result, if we have 1 million rows, then we query the above model, whereas we can estimate the time to 3 minutes, then we will lose time for 3 minutes just a query, then query again with the following conditions hold, until the conditions can not be found anymore. Very heavy especially in our computer resources are limited.
My advice, do not be too often use WHERE 1. Use of certain conditions only. But most importantly in terms of searching query index is always used when we are MyISAM tables, because the index will make it easier for us to do searching or JOIN and does not make us long in finding something on the table.
Use of Sub-Sub-Query is essentially the same as sub query, but differ only in the nested sub-queries. Examples are
“SELECT name FROM (
SELECT name FROM TABLE_STUDENT WHERE ID NOT IN (
SELECT ID FROM WHERE TABLE_GRADE GRADE IN ( ‘E’, ‘F’)
)
) U.S. TABLE_X ”
We can see that the use of sub queries above is very heavy when we get row is very hard processing, even more so as there are in the sub JOIN query. So the best solution is that we find a sub-sub-query. Because the model of the sub query is to create a temporary table, then the temporary table query with the conditions we want, so that what appears is the result of a temporary table instead of the table we query. It is suitable if you need a job that requires a lot of sub-queries.
Saving Images into MySQL Database
by Abu Aisyah on Mar.31, 2008, under Linux, Ngoprek, Open Source, PHP, Programming, mysql
Actually this question has been frequently asked with me to forums, even in infolinux, or the other PHP & MySQL forums. And they are nobody can answer it. Eventough there are making a not fine tutorial. But Alhamdulillah, at last I found the way and the right way to save an image to database.
Saving image files or mp3 or video, we usually known a data type name BLOB (Binary Large Objects). BLOB found in many database where it can handle big of transaction of data, like Oracle, MySQL, MS SQL Server,etc.
Functions PDO PHP 5.1
by Abu Aisyah on Mar.29, 2008, under Catatanku, Linux, PHP, mysql
Object Oriented Programming di PHP bukanlah sebuah hal yang baru. Bahkan OOP sejak di PHP 4 sudah ada, dan di PHP 5, sekarang ini sudah dilakukan pengembangan. Beberapa waktu lalu saya sempat kebingungan membuat kode OOP untuk transaksi database dengan menggunakan database MySQL.
Well, walaupun sudah menemukannya dengan script EzSQL, tapi ternyata di PHP 5.1 ke atas sudah tersedia sendiri di functionsnya. Berikut sedikit catatan mengenai PDO. PDO (PHP Data Objects) merupakan sebuah extensions yang sangat ringan untuk koneksi sebuah database, yang secara konsisten mengakses database via PHP. Masing-masing database driver yang mengimplementasikan interface PDO dapat mengakses database secara spesifik seperti layaknya functions extensi pada umumnya.
Kalau anda pernah menggunakan ODBC untuk sebuah koneksi ke database, misalnya anda memakai sebuah koneksi untuk database besar seperti Oracle, barangkali anda perlu mencoba PDO ini. Karena untuk versi 5.1 ke atas sudah tersedia di dalam paket PHP.
(continue reading…)
Mengatasi Pembatasan Import SQL di MySQL
by Abu Aisyah on Mar.01, 2008, under Ngoprek, Open Source, PHP, Programming, mysql
Sering kali kita mempunyai sebuah database yang sangat besar yang butuh diimport. Misalnya sebuah kejadian. Kita diberikan sebuah mesin server baru. Yang mana data-data dari server yang lama harus dipindah ke server yang baru. Bagi sebagian orang mungkin bisa dengan mudah menjalankan mysql namadatabase < namafileimport. Itu di linux, kita bisa dengan mudah melakukannya.
Bagaimana dengan orang yang nggak faham, atau mungkin newbie dan dia menggunakan sistem Operasi Microsoft Windows? Biasanya orang-orang yang bekerja seputar HTTP. Mereka akan menggunakan phpMyAdmin untuk mengurus database mysql mereka. Saya juga menggunakannya. Selain karena fiturnya yang bagus. PhpMyAdmin juga memberikan sebuah kemudahan yang bisa dengan mudah dipakai bahkan oleh orang yang belum mengerti SQL ataupun database sebelumnya.
(continue reading…)




