⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqllecture.html

📁 黑客培训教程
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<BR>&lt;d4J1nX> SELECT contact_name FROM people p,contact c WHERE p.contact_id=c.contact_id

AND forename = 'John'

<BR>&lt;d4J1nX> Notice the c and p used for an alias and to remove ambiguity

<BR>*** WishGenie has quit IRC (Quit: i gotta reboot)

<BR>*** cupelmen has quit IRC (Quit: time to sleep...)

<BR>&lt;d4J1nX> That statement will pull back the contact names for all

the people called John

<BR>&lt;d4J1nX> On an off note..

<BR>&lt;d4J1nX> Say we had a drop down/combo box on our webpage

<BR>&lt;d4J1nX> And we wanted the full details of a particular person

<BR>*** makzee has quit IRC (Ping timeout: 180 seconds)

<BR>*** SpiderMan has joined #bsrf

<BR>*** ChanServ sets mode: +o SpiderMan

<BR>&lt;d4J1nX> In the drop box we would have the details "John Woods"

or "Chris Simms"

<BR>*** bluehaze has quit IRC (Ping timeout: 180 seconds)

<BR>&lt;d4J1nX> But the actual value would be the corresponding id in the

table

<BR>&lt;Mikkkeee> hail spider

<BR>&lt;SpiderMan> hey

<BR>&lt;AZTEK> Spidey

<BR>*** ken has quit IRC (Quit: )

<BR>&lt;AZTEK> all hail SpiderMan

<BR>&lt;SpiderMan> hey AZTEK

<BR>*** Capt_InsaneO has joined #bsrf

<BR>&lt;d4J1nX> Depending on the langauge being used we loop through each

record brought back from the query and have a formselectOption for each

<BR>*** Mezzano has quit IRC (Read error: 113 (No route to host))

<BR>&lt;d4J1nX> SELECT people_id, forename FROM people;

<BR>&lt;d4J1nX> The forename would be in the dropdown

<BR>*** torpor has left #bsrf

<BR>&lt;d4J1nX> But behind the scenes the actual value for that selection

is the id

<BR>*** Capt_InsaneO has left #bsrf

<BR>*** mezzano has joined #bsrf

<BR>*** acid519 has joined #bsrf

<BR>&lt;Devil_Panther> oh... hi spidy

<BR>&lt;d4J1nX> This is moving on to front end languages though and since

php seems to be very popular at the moment, Aztek will take it form here

<BR>&lt;d4J1nX> Hey Spider :-)

<BR>&lt;SpiderMan> hi

<BR>&lt;SpiderMan> sorry to disturb

<BR>&lt;d4J1nX> np

<BR>&lt;AZTEK> ok i guess its php time

<BR>&lt;AZTEK> and we are going to php and not perl

<BR>&lt;SpiderMan> so soon?

<BR>&lt;AZTEK> lets hit it spidy\

<BR>&lt;AZTEK> yea

<BR>&lt;AZTEK> ok

<BR>&lt;SpiderMan> nothing more of SQL?

<BR>&lt;SpiderMan> WHERE clause

<BR>&lt;Mikkkeee> php now

<BR>&lt;SpiderMan> db normilization

<BR>&lt;SpiderMan> ok

<BR>&lt;Devil_Panther> AZTEK,,, i guess you preffer php on perl... huh?!

<BR>&lt;AZTEK> we did the WHERE

<BR>&lt;AZTEK> yea

<BR>&lt;d4J1nX> Thats already been done Spider

<BR>&lt;SpiderMan> ok

<BR>&lt;d4J1nX> Plus normalisation - although not alot

<BR>&lt;SpiderMan> ok then I guess it is php time :)

<BR>&lt;AZTEK> mysql is the prefered datbase engine of choice by us phpers

<BR>&lt;SpiderMan> because it's small, fast, and cheap

<BR>&lt;AZTEK> what make us choose mysql over any other

<BR>&lt;d4J1nX> You want me to go into normalisation more first Aztek?

<BR>&lt;AZTEK> exactly

<BR>&lt;AZTEK> cant beat free

<BR>&lt;SpiderMan> also it's avaliable on many platforms

<BR>&lt;Devil_Panther> ok ok...

<BR>&lt;Devil_Panther> LECTURE PLS

<BR>&lt;AZTEK> yea any platform apache and php run mysql does

<BR>&lt;Devil_Panther> lol

<BR>*** BaGeL has joined #bsrf

<BR>&lt;AZTEK> ok

<BR>&lt;AZTEK> mysql_connect();

<BR>&lt;AZTEK> you have to connect to the mysql host

<BR>&lt;d4J1nX> Can php use access databases Az?

<BR>&lt;AZTEK> usually localhost

<BR>&lt;AZTEK> d4J1nX: yes

<BR>&lt;AZTEK> actually i am waiting for spidy to give me the syntax since

i don't have my manual open

<BR>&lt;SpiderMan> for mysql_connect()?

<BR>&lt;SpiderMan> it's localhost, username, password

<BR>&lt;AZTEK> yea

<BR>&lt;SpiderMan> in strings

<BR>&lt;AZTEK> yea but port

<BR>&lt;AZTEK> and stuff

<BR>&lt;SpiderMan> if no port is given it uses the default

<BR>&lt;AZTEK> int mysql_connect ([string hostname [:port] [:/path/to/socket]

[, string username [, string password]]])

<BR>&lt;SpiderMan> you don't have to provide the port unless it's different

then the standard

<BR>&lt;AZTEK> yea

<BR>&lt;AZTEK> i was wanting the full atribs :)

<BR>&lt;SpiderMan> ah, I'll open my docs

<BR>&lt;AZTEK> ok mysql_connect() returns a database handle

<BR>&lt;AZTEK> that we will use later for other things

<BR>&lt;SpiderMan> you should always check for a valid handle

<BR>&lt;AZTEK> we use mysql_query();

<BR>&lt;AZTEK> te send a query which d4J1nX when over the standard querys

earlier

<BR>&lt;SpiderMan> $con= mysql_connect("localhost", "jared", "pass"); if(!$con)

{die("can't connect!");}

<BR>*** Shiva_Shanti has joined #bsrf

<BR>&lt;AZTEK> mysql_query("SELECT * FROM people");

<BR>&lt;SpiderMan> int mysql_query (string query [, int link_identifier])

<BR>*** d4J1nX has quit IRC (Ping timeout: 180 seconds)

<BR>&lt;AZTEK> $result = mysql_query("SELECT * FROM people");

<BR>&lt;AZTEK> thats will return what mysql said for the query

<BR>&lt;SpiderMan> then you can use functions such as mysql_fetch_array()

to get the results

<BR>&lt;AZTEK> yea

<BR>&lt;AZTEK> umm thats the reson php is popular for database use its

really easy :)

<BR>*** acid519 has quit IRC (Ping timeout: 180 seconds)

<BR>&lt;AZTEK> use mysql_drop_db("database name"); to delete a database

<BR>&lt;AZTEK> use mysql_create_db("database name"); to create a databse

<BR>&lt;AZTEK> anything else spidy

<BR>&lt;AZTEK> like i said its easy

<BR>&lt;SpiderMan> int mysql_create_db (string database name [, int link_identifier])

<BR>&lt;SpiderMan> let's give an example

<BR>&lt;AZTEK> ok

<BR>&lt;AZTEK> from the start

<BR>&lt;SpiderMan> how about something to pull news out of a db

<BR>*** d4J1nX has joined #bsrf

<BR>&lt;AZTEK> ok

<BR>&lt;SpiderMan> let's say a database is set up with an id field and

a news field

<BR>&lt;SpiderMan> to get the news out we could do this

<BR>&lt;SpiderMan> if (!mysql_connect("host", "user", "pass")) {die("error!");}

<BR>*** TCL has joined #bsrf

<BR>*** ChanServ sets mode: +v TCL

<BR>&lt;SpiderMan> mysql_select_db("db");

<BR>&lt;AZTEK> |ID|NEWS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

|

<BR>&lt;AZTEK> --------------------------

<BR>&lt;AZTEK> |1 |.....................|

<BR>&lt;AZTEK> |2 |.....................|

<BR>&lt;AZTEK> |3 |.....................|

<BR>&lt;AZTEK> |4 |.....................|

<BR>&lt;AZTEK> |5 |.....................|

<BR>&lt;SpiderMan> that's what the db table would look like

<BR>&lt;SpiderMan> $result= mysql_query("SELECT * FROM news ORDER BY id

DESC);

<BR>&lt;SpiderMan> we use that to select the news and id out

<BR>&lt;SpiderMan> then using a while loop fetch all the data

<BR>*** Shiva_Shanti has quit IRC (Quit: eat, bbl)

<BR>&lt;SpiderMan> while($row= mysql_fetch_array($result)) {

<BR>&lt;SpiderMan> $news= $row["NEWS"];

<BR>&lt;SpiderMan> $id= $row["ID"];

<BR>*** divinator has quit IRC (Ping timeout: 180 seconds)

<BR>&lt;SpiderMan> echo "id= $id&lt;br>";

<BR>*** N0_Nick has quit IRC (Ping timeout: 180 seconds)

<BR>&lt;SpiderMan> echo "news= $news&lt;br>";

<BR>&lt;SpiderMan> }

<BR>&lt;SpiderMan> and after that we close the connection to the database

<BR>&lt;AZTEK> ok i tought spidy was just pulling this out of one of his

scripts

<BR>&lt;AZTEK> never mind

<BR>&lt;SpiderMan> heh nope

<BR>&lt;SpiderMan> just wrote it up right now

<BR>&lt;AZTEK> ok

<BR>&lt;AZTEK> using my little impromtu database

<BR>&lt;SpiderMan> heh yup

<BR>&lt;SpiderMan> question time?

<BR>&lt;AZTEK> .mode #bsrf -m

<BR>*** AZTEK sets mode: -m

<BR>&lt;freakOVER[away]> whew

<BR>*** N0_Nick has joined #bsrf

<BR>&lt;UnHaFox> =)

<BR>&lt;freakOVER[away]> i felt so

<BR>&lt;freakOVER[away]> muzzled

<BR>&lt;SpiderMan> heh

<BR>*** acid519 has joined #bsrf

<BR>&lt;UnHaFox> ah got it one the log file;)

<BR>&lt;AZTEK> damn laptop

<BR>&lt;mezzano> we can talk again ;)

<BR>&lt;AZTEK> well its not over

<BR>&lt;d4J1nX> Explain each line of code Spider

<BR>&lt;AZTEK> d4J1nX

<BR>&lt;AZTEK> is about to do perl

<BR>&lt;UnHaFox> not over?

<BR>&lt;N0_Nick> hey i got disconnected

<BR>&lt;SpiderMan> ok

<BR>&lt;N0_Nick> man

<BR>&lt;freakOVER[away]> oo

<BR>&lt;SpiderMan> wait I want to give some tips before we go to perl

<BR>&lt;freakOVER[away]> perl

<BR>*** AZTEK sets mode: +m

<BR>&lt;SpiderMan> ok so first we connect to the database using mysql_connect()

<BR>*** acid519 is now known as _acid519-

<BR>*** pixel_chomp has joined #bsrf

<BR>&lt;SpiderMan> we test to make sure we could connect in the if clause

<BR>&lt;AZTEK> if (!mysql_connect("host", "user", "pass")) {die("error!");}

<BR>&lt;SpiderMan> if we can't connect we exit the script with the error

message

<BR>*** _ciR_ has joined #bsrf

<BR>&lt;SpiderMan> in a real script you would give a better error

<BR>&lt;AZTEK> yea like

<BR>&lt;AZTEK> "You fucked it up"

<BR>&lt;AZTEK> lol

<BR>&lt;AZTEK> $result= mysql_query("SELECT * FROM news ORDER BY id DESC);

<BR>&lt;SpiderMan> in fact if you want to get the error mysql gives you,

you can use the function mysql_error()

<BR>&lt;AZTEK> now we query the database asking for all info in the databse

news and we want it ordered by the id feild decending

<BR>&lt;AZTEK> you forgot your "

<BR>*** SySt3mShk has left #bsrf

<BR>&lt;AZTEK> $result= mysql_query("SELECT * FROM news ORDER BY id DESC");

<BR>*** SySt3mShk has joined #bsrf

<BR>&lt;SpiderMan> heh whoops

<BR>&lt;AZTEK> &lt;SpiderMan> while($row= mysql_fetch_array($result)) {

<BR>&lt;AZTEK> &lt;SpiderMan> $news= $row["NEWS"];

<BR>&lt;AZTEK> &lt;SpiderMan> $id= $row["ID"];

<BR>&lt;AZTEK> *** divinator (Oper@box.sk) Quit (Ping timeout: 180 seconds)

<BR>&lt;AZTEK> &lt;SpiderMan> echo "id= $id&lt;br>";

<BR>&lt;AZTEK> *** N0_Nick (hgfhf@202.179.171.BOX-24341) Quit (Ping timeout:

180 seconds)

<BR>&lt;AZTEK> &lt;SpiderMan> echo "news= $news&lt;br>";

<BR>&lt;AZTEK> &lt;SpiderMan> }

<BR>&lt;SpiderMan> that says while there are rows to fetch, get them

<BR>&lt;AZTEK> here we are looping

<BR>&lt;AZTEK> yea

<BR>-d4J1nX- I have to go here, going out, I will speak soon

<BR>*** UnHaFox has left #bsrf

<BR>&lt;AZTEK> $row becomes a hask array with the column names as identifiers

<BR>-d4J1nX- say bye for meeee

<BR>&lt;SpiderMan> hash array*

<BR>&lt;AZTEK> yea hash

<BR>*** d4J1nX has quit IRC (Quit: )

<BR>&lt;AZTEK> and echo is self explainatory

<BR>&lt;SpiderMan> yeah

<BR>&lt;SpiderMan> just print it out

<BR>*** UnHaFox has joined #bsrf

<BR>&lt;AZTEK> thats about it

<BR>&lt;SpiderMan> when the script finishes the connection to the db will

close

<BR>&lt;SpiderMan> also just a tip

<BR>&lt;AZTEK> now

<BR>&lt;SpiderMan> if you are using larger scripts

<BR>&lt;SpiderMan> use mysql_pconnect()

<BR>*** AZTEK sets mode: -m

<BR>&lt;SpiderMan> it will save memory

<BR>&lt;AZTEK> for persestant connection

<BR>&lt;UnHaFox> ah=)

<BR>&lt;AZTEK> so they wont keep connecting with each user

<BR>*** divinator has joined #bsrf

<BR>&lt;reptile> ;)

<BR>&lt;UnHaFox> ?

<BR>&lt;SpiderMan> so questions?

<BR>&lt;freakOVER[away]> lol rep

<BR>&lt;_ciR_> oh

<BR>&lt;_ciR_> lets kill reptile

<BR>&lt;_ciR_> lol

<BR>&lt;divinator> yo

<BR>&lt;AZTEK> now i guess Mikkkeee will cover hacking sql

<BR>&lt;BaGeL> sup div

<BR>&lt;_ciR_> he didnt show up

<BR>&lt;UnHaFox> yes i have one, but this one doent concern this subject,

so can i ask it?

<BR>&lt;Mikkkeee> you guys are done?

<BR>&lt;AZTEK> yea

<BR>&lt;reptile> ;()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -