Entries Tagged 'MySQL' ↓

How to Create a FULLTEXT index on MySQL Table for Fulltext Match Search

To setup a table to work with a MySQL FULLTEXT Match query, you must first match sure the table is MyISAM. You can alter your table using this query:

ALTER TABLE `table_name` ENGINE=MyISAM;

Next you need to create an index of fields want to search through. You can use this query as an example:

ALTER TABLE `table_name` ADD FULLTEXT `index_name` (`field_name_1`,`field_name_2`,`field_name_3`,`field_name_4`);

Now you can run a match query!

MySQL Database: Got error 28 from storage engine

I go this error this morning running a ORDER BY RAND()

My server’s disk was full. I went into my backups, tmp, and logs folder and cleaned up.

MySQL Case sensitive and Case insensitive search with Match and Like

This post teaches you how to set your MySQL search queries to be Case sensitive or case insensitive.

It’s all in the database collation. MySQL by default search case insensitive. In phpMyAdmin or or Putty change the Collation of your fields. Collations that are binary search case-sensitive. Collations that end with _ci like latin1_swedish_ci are case insensitive (ci is an acrynm for case insensitive.

To change your Collations quickly run this code in a loop:

ALTER TABLE tablename CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci;

Create a Javascript Array with PHP from a MySQL Database Table

Wrote this function to check email addresses already in a database, so I dont have to change pages, and check with javascript. Problem: it exposes your whole email list to the public in the source code, and the source code can become a monster length. So it isnt practical, but it works. (I’m not using it to check emails)

The script proves useful to do other things with javascript and spawn arrays to manipulate data… etc.

function jarray(){

$sql = "SELECT * FROM <strong>table_name</strong> LIMIT 0, 100000000";
$jarray = "var <strong>your_array</strong> = new Array();\n\t\t";
$i = 0;
$q = mysql_query($sql);
while($object = mysql_fetch_object($q)){
$jarray = $jarray."<strong>your_array</strong>[{$i}] = \"{$object-&gt;<strong>field_name</strong>}\";\n\t\t";
$i++;
}

print $jarray."\n";
}

Put your own info where the Text is bold

PHP MySQL Count Query Using Where Clause

Here is an example of a function that was created to count the number of book spreads attached to a certain book number. The problem was there were more than one book number attached to a whole table of bookspreads. By using SQL COUNT and WHERE it is possible to find the total count of entries with the same field input.

$book // the book number i wanted to count if a spread was attached to it

function spreadcount($book){
$query = “SELECT COUNT(*) FROM table WHERE book={$book} “;
$result = mysql_query($query) or die(mysql_error());
echo mysql_result($result,0); // 0 pulls the first result which is our magic number.

}