Home > Archive > Linux/Unix > January 2003 > Anyone into MySQL?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Anyone into MySQL?
onoski

2002-12-30, 4:41 am

Just curious as to know if anyone is into mysql the open source database. Pls, a recommendation for a good book on this would be appreciated. I still think databases are the way to go as there are too many people saturating networking etc. Just my humble opinion or what's your say on this topic? Keep the knowledge base flowing and best wishes for the new year well at least I hope it would be better than 2002
anaconda

2002-12-30, 8:03 pm

I'm into MySQL bigtime. There is no cert for it yet but they're working on one. Search MySQL certification beta if you wanna beta test the exam. I like Paul DuBois book on mySQL from new riders press.
Mr. Linux Guy

2002-12-31, 9:26 am

I use it daily. The combo I use (and I think most UNIX hackers use) is Apache, MySQl, and PHP/Perl to run their websites. The "teach Yourself MySQL In 24 Hours" by Julie C. Meloniis a good book for abslute gnubies, but isn't that depthful. The best book period is "PHP and MySQL Web Development" by Luke Welling and Laura Thomson with "MySQL/PHP Database Applications" by Jay Greenspan and Brad Bulger coming in a close second. You will need to learn to program to effectively use MySQL, but it is fairly easy and once you have your working environment set up, maintaining your web site will be much easier. Some excellent "getting warmed up" exercises would be trying to code yourself a guestbook and later a helpdesk system using the above tools. (Do not uset hese in production until you know all of the security issues, mind you.) Post any questions you might have here. We'd be glad to help.
iggy4270

2003-01-08, 6:11 am

quote:
Originally posted by Mr. Linux Guy -You will need to learn to program to effectively use MySQL
How does it respond to Python? Any Quirks?
Mr. Linux Guy

2003-01-08, 6:38 am

quote:
Originally posted by iggy4270
How does it respond to Python? Any Quirks?


I usually use PHP, but youy can use Python with it quite well. Both play well with others. You'll need to install the modules from: http://www.mysql.com/downloads/api-python.html if you haven't already. You can get some stuff at sourceforge as well: http://sourceforge.net/projects/mysql-python . To connect to the db using Python, you can do something like this:

code:
#!/usr/bin/python import MySQLdb # connect db = MySQLdb.connect(host="najee", user="randy", passwd="beere.es.g00d", db="myppdb") cursor = db.cursor() cursor.execute("SELECT price FROM beer") result = cursor.fetchall() for record in result: print record[0] , "-->", record[1]


This will fetch the data using a cursor, and from then on you can manipulate your data however you like in the main of the program. Updates and deletes are done the same way:

cursor.execute("""INSERT INTO beer (name, price) VALUES ("Grolsch",
"3.25")""")

Mainly you'd just need to get familiar with the MySQL module and what the functions available to you are.
iggy4270

2003-01-08, 8:49 am

Thanks MLG. I've been playing with Python for a while and I just find that I'm most comfortable with it. I might start playing with some Perl later on down the line as I start getting more comfortable with Red Hat 8.0
Mr. Linux Guy

2003-01-08, 9:13 am

Actually, Python allows you to write much cleaner code than Perl does. Most of my perl programs I have trouble understanding a week later. For example, I coded this up in Perl about a year ago to do some web work:

code:
#!/usr/local/bin/perl -w $/ = ".\n"; while (<> ) { next if !s/\b([a-z]+)((\s|<[^>]+> )+)(\1\b)/\e[7m$1\e[m$2\e[7m$4\em/ig; s/^([^\e]*\n)+//mg;; s/^/$ARGV: /mg; print; }


Pretty, huh? Python allows you to write more readable programs so if you like it, you might as well stick with it. Usually nowadays, webmasters are leaning more to PHP since it is compiled directly into Apache and thus does not have to fork a new process in order to perform an action, whereas Perl or Python are usually excuted as CGI scripts which causes a small delay while a new process is called. At any rate, all three languages are free and Open Source, so take the one you like the most and learn it well. Let me know if you run into any snags.
iggy4270

2003-01-08, 11:44 am

Thanks. I was steered toward python.org about a year and a half ago, and I really didn't start getting into it until about 6 months ago. I just picked up a copy of O'Reilly's Learning Python, and to be honest with you I am going to stick with it for a while. As someone who has had no programming experience I feel really comfortable with it. What impressed me the most was meeting an M.I.T. Phd who won't use anything else but Python. There's just so many languages out there that it can become very confusing for the newbie.
prezbedard

2003-01-08, 11:45 am

I am familiar with MySQL and heard of PHP which I am guessing is a server side scripting language.

I don't need any high detailed information
just a general idea.

My webhost account has MySQL and myPHPadmin. These are both accessed via the online control panel. I haven't done much beyond looking at it and seeing how it works. Creating the MySQL database seems straight forward I use the online tool to create tables with the number of fields I want. My question is do I use php to access and reference the data in the MySQL database. For instance I create a simple table and make a webpage with a form using PHP to Query the database? A simple example
would be nice.

I also have MySQL and Apache on my Linux box at home. How do I determine if I have PHP installed or not?

Thanks
Mr. Linux Guy

2003-01-08, 12:35 pm

quote:
Originally posted by prezbedard
I am familiar with MySQL and heard of PHP which I am guessing is a server side scripting language.

I don't need any high detailed information
just a general idea.

My webhost account has MySQL and myPHPadmin. These are both accessed via the online control panel. I haven't done much beyond looking at it and seeing how it works. Creating the MySQL database seems straight forward I use the online tool to create tables with the number of fields I want. My question is do I use php to access and reference the data in the MySQL database. For instance I create a simple table and make a webpage with a form using PHP to Query the database? A simple example
would be nice.

I also have MySQL and Apache on my Linux box at home. How do I determine if I have PHP installed or not?

Thanks



Try

$ rpm -qi php

or

$ which php

You use PHP to do any processing you need, generally to output a website based upon information in a database. For example, on my website, I have a phone list for the organisation. The page is dynamically generated using the following code:

code:
<? //Create db connection $conn = db_connect(); if (!$conn) { return "The phone list is unavailable - please try later.\n"; do_html_footer(); exit; } else { $sql = "SELECT * FROM phone_list ORDER BY pos"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { // Set color if($color == "cccccc") { $color = "dddddd"; } else { $color = "cccccc"; } $prefix = $row["prefix"]; $lname = $row["lname"]; $fname = $row["fname"]; $title = $row["title"]; $location = $row["location"]; $room = $row["room"]; $phone = $row["phone"]; if((!$prefix)&&(!$lname)&&(!$fname)&&(!$location)&&(!$room)&&(!$phone)) { // Print title lines print("<tr colspan=7>\n"); print("<td bgcolor=#D3DCE3 colspan=7><font size=2 face=verdana><b>$title</b></font></td>\n"); print("</tr>\n"); } else { // Print phone entries print("<tr>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$fname $lname</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$title</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$location</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$room</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$phone</font></td>\n"); print("</tr>\n"); } } } ?>


This allows the PHP to connect to the MySQL database, then fetch what information it needs, then sends it to the correct data elements in the PHP code, and then PHP formats the page up in borwser-ready HTML. If you'd view the source of the page, all you would see is the HTML output.

The PHP functions are stored in a sibling directory to the Apache root (called phpconf) and the operative one in the above code that gets called looks something like this:

code:
<? function db_connect() { $result = mysql_pconnect("10.3.6.134", "webdude", "fj6.09;sl"); if (!$result) return false; if (!mysql_select_db("webdb")) return false; return $result; } // Place entries into the log table function logger($pkey,$message) { // connect to db $conn = db_connect(); if (!$conn) return 0; // Set ip number $ipnum = $REMOTE_ADDR; // check if username is unique $result = mysql_query("insert into log (pkey,ipnum,message) values ('$pkey','$ipnum','$message')"); if (!$result) return 0; } ?>


All you'd have to do is change the connect particulars for when this function is called. Like the username, passwd, database being called, and IP address of the database server.
Mr. Linux Guy

2003-01-08, 12:40 pm

quote:
Originally posted by iggy4270
Thanks. I was steered toward python.org about a year and a half ago, and I really didn't start getting into it until about 6 months ago. I just picked up a copy of O'Reilly's Learning Python, and to be honest with you I am going to stick with it for a while. As someone who has had no programming experience I feel really comfortable with it. What impressed me the most was meeting an M.I.T. Phd who won't use anything else but Python. There's just so many languages out there that it can become very confusing for the newbie.


Python is a good general-purpose language to stick with. If I have a large program to do in C, I usually prototype it in Python. You may want toget "Programming Python" and the "Python Cookbook" later as well, as they have tons of useful hints in it. They will show you how to do lots of this stuff. Although in defence of my favourite programming language, I feel it necessary to point out that Pythin itself is written in C.

Really though, there are fewer better languages than Pythin to begin learning how to program with. The Basic family doesn't count. You can hardly do anything with them.
Mr. Linux Guy

2003-01-08, 12:55 pm

quote:
Originally posted by prezbedard
I am familiar with MySQL and heard of PHP which I am guessing is a server side scripting language.

I don't need any high detailed information
just a general idea.

My webhost account has MySQL and myPHPadmin. These are both accessed via the online control panel. I haven't done much beyond looking at it and seeing how it works. Creating the MySQL database seems straight forward I use the online tool to create tables with the number of fields I want. My question is do I use php to access and reference the data in the MySQL database. For instance I create a simple table and make a webpage with a form using PHP to Query the database? A simple example
would be nice.

I also have MySQL and Apache on my Linux box at home. How do I determine if I have PHP installed or not?

Thanks



BTW, yes, it's considered a scripting language, but is much faster than Perl or Python since it is compiled as an Apache module and does not need to fork a new process like Apache has to do with CGI. (If you are using any other web server, I am not sure there is much of an advantage). PHP, unlike Perl and Python, however, is striclty a web scripting language and is not a general purpose language, The code looks like dumbed-down C code as you can see from the above.
prezbedard

2003-01-08, 7:05 pm

quote:
Originally posted by Mr. Linux Guy
Try

$ rpm -qi php

or

$ which php

You use PHP to do any processing you need, generally to output a website based upon information in a database. For example, on my website, I have a phone list for the organisation. The page is dynamically generated using the following code:

code:
<? //Create db connection $conn = db_connect(); if (!$conn) { return "The phone list is unavailable - please try later.\n"; do_html_footer(); exit; } else { $sql = "SELECT * FROM phone_list ORDER BY pos"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { // Set color if($color == "cccccc") { $color = "dddddd"; } else { $color = "cccccc"; } $prefix = $row["prefix"]; $lname = $row["lname"]; $fname = $row["fname"]; $title = $row["title"]; $location = $row["location"]; $room = $row["room"]; $phone = $row["phone"]; if((!$prefix)&&(!$lname)&&(!$fname)&&(!$location)&&(!$room)&&(!$phone)) { // Print title lines print("<tr colspan=7>\n"); print("<td bgcolor=#D3DCE3 colspan=7><font size=2 face=verdana><b>$title</b></font></td>\n"); print("</tr>\n"); } else { // Print phone entries print("<tr>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$fname $lname</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$title</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$location</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$room</font></td>\n"); print("<td bgcolor=$color><font size=1 face=verdana>$phone</font></td>\n"); print("</tr>\n"); } } } ?>


This allows the PHP to connect to the MySQL database, then fetch what information it needs, then sends it to the correct data elements in the PHP code, and then PHP formats the page up in borwser-ready HTML. If you'd view the source of the page, all you would see is the HTML output.

The PHP functions are stored in a sibling directory to the Apache root (called phpconf) and the operative one in the above code that gets called looks something like this:

code:
<? function db_connect() { $result = mysql_pconnect("10.3.6.134", "webdude", "fj6.09;sl"); if (!$result) return false; if (!mysql_select_db("webdb")) return false; return $result; } // Place entries into the log table function logger($pkey,$message) { // connect to db $conn = db_connect(); if (!$conn) return 0; // Set ip number $ipnum = $REMOTE_ADDR; // check if username is unique $result = mysql_query("insert into log (pkey,ipnum,message) values ('$pkey','$ipnum','$message')"); if (!$result) return 0; } ?>


All you'd have to do is change the connect particulars for when this function is called. Like the username, passwd, database being called, and IP address of the database server.





Thanks fo the info. I assume the I save both sets of code as .php files?

Seems to very interesting indeed. I'll give it a try when i get some free time.

At the moment I'm studying for Network+,
voluteering, job searching and I'm putting together a Intro to HTML course I will be teaching at SalemCyberSapce.

Thanks Again
wildscribe

2003-01-08, 7:45 pm

Python is an excellent first language to learn. Just figure out how variables, loops, arrays and if/else statements work and you'll be able to use this knowledge to quickly learn other languages like Perl, PHP, Java, etc. Python was first first language and it has served me well.

Lots of good MySQL advice on this thread. I just want to add that you can download the database for free from www.MySQL.com There are versions for Windows and various *nix flavors.

-- Wild
Mr. Linux Guy

2003-01-09, 6:36 am

quote:
Originally posted by prezbedard
Thanks fo the info. I assume the I save both sets of code as .php files?

Seems to very interesting indeed. I'll give it a try when i get some free time.

At the moment I'm studying for Network+,
voluteering, job searching and I'm putting together a Intro to HTML course I will be teaching at SalemCyberSapce.

Thanks Again



Yeah, just save both as php files. The great thing about this also is that it is all open source and most people just share their code once they write something up. I got Sams "PHP and MySQL Web Development" by Thompson and Welling and most of the code for a complete helpdesk and content management system was already there. I mainly just had to alter a few things to suit my company's needs. Also there are lots of projects on the web (especially at sourceforge) that just post stuff like this free for the taking. Sometimes they are works in progress, so you can actually contribute to the process by testing the stuff out and reporting bugs to the developers (in a well-managed/manned project, the bugs are usually fixed within a day or so). When you go to production, you'll look like a genius without having done much work at all.
onoski

2003-01-09, 7:04 am

It's nice to see how this thread is developing. Keep the knowledge base flowing guys
Mr. Linux Guy

2003-01-09, 7:12 am

If interested, there is a small project combining PHP and MySQL calle phphelpdesk at sourceforge: http://phphelpdesk.sourceforge.net/ -- version 1.0 hasn't been released yet, but if you d/l it and recommed features that you would like to see and report bugs that you find, you'd be helping in the development process. You could also learn a lot in the process, as the codebase is really pretty simple and you get to see all of it. Simple projects like this are great ways to learn.
iggy4270

2003-01-09, 10:08 am

Great link. Thanks MLG
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2009 examnotes.net