NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Webmaster Tutorials
Reload this Page MySQL Tips

Webmaster Tutorials Instructional webmaster-related how-to's and tutorials.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 10-15-2005, 01:25 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Sep 2005
Posts: 30
shahid_146 is an unknown quantity at this point
 



MySQL Tips


http://www.binarytrends.com/article_...Might-Not-Know

MySQL is a database server suitable for small and a little bigger sized database applications. It has been the all time favourite since its creation. It works on windows as well as Unix / Linux but when run on Unix / Linux, it can provide multithreading which boosts its performance a lot. MySQL supports standards SQL (ANSI) and can be used with a variety of web technologies pretty efficiently. PHP with MySQL is one of the best combinations used by millions of websites and they are happy with it. And the beauty of both PHP and MySQL is that they are open source meaning FREE!! In this article I will describe a few MySQL functions, some of them I had been desperate for back at some point in my web development journey.
????: NamePros.com http://www.namepros.com/webmaster-tutorials/131891-mysql-tips.html

Last Inserted Row Number

Often when working with multiple tables, you run an INSERT query on a table and then you need to find out its ID in order to be able to use it to update another table. I used to use the MAX function to perform this until I found this useful function called mysql_insert_id. This function, when given the link identifier, retrieves the AUTO_INCREMENT ID of the last INSERT operation. Below is an example of how it can be used:

// Insert query for a table with an AUTO_INCREMENT field named order_id
// the values for the rest of the fields product name, quantity, price are being inserted

$ins_qry = “INSERT INTO orders values (‘Umbrella’,’2’,’50’)”;

//Run the query myConn represents the connetion string

$qryresource = mysql_query($ins_qry, $myConn);

// Get the inserted ID

$inserted_id = mysql_insert_id($myConn);

// $inserted_id now contains the id for the last inserted row

NOTE: If the link identifier is not specified, the last link opened by mysql_connect() is assumed.


FULLTEXT Search

When working with searches on text fields in MySQL, the LIKE queries are very commonly used. The situation gets complicated when it comes to using them on large tables. MySQL now provides an alternative, which is easy to use and more efficient. The FULLTEXT can create indexes of CHAR, VARCHAR and TEXT fields and organise them efficiently. It can also return a relevance value based on how well each result matched the words a user is looking for. To CREATE a table and ask MySQL to start indexing a field or set of fields you would write something like this:

CREATE TABLE articles (
-> article_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
-> title VARCHAR(200),
-> body TEXT,
è FULLTEXT (title,body)

You can also ALTER an existing table to start building an index of some of the columns:

ALTER TABLE articles ADD FULLTEXT art_search (title, body)

You will then need to INSERT or MODIFY a record to get MySQL start indexing it.
With the FULLTEXT indexing turned on you can use the MATCH() function to search for a string against the columns included. By default the search is not case-sensitive but you can change it by using a binary collation. The following SELECT statement will return all indexes in the title and body columns against the word “MySQL database”, along with the relevance score of each result:

SELECT id, body, MATCH (title,body) AGAINST
-> ('MySQL Database') AS score
-> FROM articles WHERE MATCH (title,body) AGAINST
è ('MySQL Database');


The MySQL FULLTEXT implementation regards any sequence of true word characters (letters, digits, and underscores) as a word. That sequence may also contain apostrophes ('), but not more than one in a row.
????: NamePros.com http://www.namepros.com/showthread.php?t=131891
For more reading on the FULLTEXT features please refer to the MySQL manual at http://dev.mysql.com/doc/refman/5.0/...xt-search.html
Last edited by shahid_146; 10-16-2005 at 02:32 AM.
shahid_146 is offline  
Old 10-16-2005, 12:55 PM   #2 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 173
brianmn is on a distinguished road
 



These are very good tips. I have been looking for a mysql autoincrement thing for a long time now. This one seems pretty easy.

But lets say i have a table like this:
ID Product Quantity
1 a 50
2 b 34
3 c 45

Now i delete the product with an id of 2 so the table looks like this:
ID product quantity
1 a 50
3 c 45

Will this variable $inserted_id, in your case with the next row i insert contain, a 4? So that i could then turn around and insert it into the mysql table.
????: NamePros.com http://www.namepros.com/showthread.php?t=131891

Or is there a better way of doing this. I just want to make it so that each record has an ID that goes up by 1 each time, and that starts at either 0 or 1.
brianmn is offline  
Old 10-17-2005, 11:47 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Sep 2005
Posts: 30
shahid_146 is an unknown quantity at this point
 



In this case $inserted_id will return 4 meaning regardless of any record you delete, the next available auto increment number will be picked by this function.
shahid_146 is offline  
Old 10-18-2005, 06:52 AM   #4 (permalink)
NamePros Regular
 
NuPagady's Avatar
Join Date: Jul 2005
Location: Lithuania
Posts: 482
NuPagady is on a distinguished road
 



Nice Article. Thanks for the link.
NuPagady is offline  
Old 10-18-2005, 01:53 PM   #5 (permalink)
NamePros Member
Join Date: Oct 2005
Posts: 173
brianmn is on a distinguished road
 



Originally Posted by shahid_146
In this case $inserted_id will return 4 meaning regardless of any record you delete, the next available auto increment number will be picked by this function.
Thanks, i'll be using this for my site now.
brianmn is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOWTO: Install the Apache Web Server, Perl, PHP, and MySQL on Windows deadserious Webmaster Tutorials 96 05-27-2007 02:24 PM
MySQL Using Transaction ?? shahid_146 Programming 0 10-10-2005 11:59 PM
Tutorial: How to Install Apache2 MySQL and PHP on Windows deadserious Webmaster Tutorials 35 09-21-2005 10:46 PM
HOW TO: Use shell to control MySQL. abdulmueid Webmaster Tutorials 16 08-27-2005 09:17 AM
Tutorial: Getting Started With MySQL (The Basics) deadserious Webmaster Tutorials 3 04-18-2004 02:17 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:19 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger