- Joined
- May 19, 2007
- Messages
- 440
- Reaction score
- 78
[PHP & MySQL] Tutorials & Examples
1. Inserting data to MySQL Table. (MySQL - Insert)
2. Select from MySQL Table WHERE. (MySQL - Where & Fetch)
3. Updating existing MySQL row. (MySQL - Update)
4. Deleting specific content from table. (MySQL - Delete)
5. What is MySQL die command? (MySQL Error Reporting)
6. How to do MySQL Configuration file? (Misc)
6B. Requiring the Configuration file? (Misc)
6C. How to use MySQL Configuration file with ex. MySQL connection? (Misc)
7. Limit for "SELECT * FROM" Query. (MySQL - Where & Fetch Result Limit)
8. Connect to IP AND Port. (MySQL - FSockOpen)
9. Setting cookie. (PHP Cookies)
9B. Page restriction by cookie. (PHP Cookie REQUIRED)
1. Inserting data to MySQL Table.
2. Select from table WHERE.
3. Updating existing row in table.
4. Deleting specific content from table.
5. What is this "or die(mysql_error());" ?
If your code doesn't work correctly it will report you information about it what's wrong.
6. Creating a MySQL Configuration File.
6B. How you can use it?
Everywhere you want to use it you must require the configuration file to receive every "shortcut" to the current document.
6C. Using a MySQL Configuration File with MySQL Connection.
7. Limit for "SELECT * FROM" Query.
8. Connect to IP AND Port.
9. Setting the cookie.
9B. Page need cookie to be shown.
This is for advanced coders.
The reason why i'm not using if(!$Con) { commands etc functions with my code in this thread is that, because all of those functions confuses new PHP coders.
Never is not too late for learning.
First learn all of these basics and after that... grinding the code.
1. Inserting data to MySQL Table. (MySQL - Insert)
2. Select from MySQL Table WHERE. (MySQL - Where & Fetch)
3. Updating existing MySQL row. (MySQL - Update)
4. Deleting specific content from table. (MySQL - Delete)
5. What is MySQL die command? (MySQL Error Reporting)
6. How to do MySQL Configuration file? (Misc)
6B. Requiring the Configuration file? (Misc)
6C. How to use MySQL Configuration file with ex. MySQL connection? (Misc)
7. Limit for "SELECT * FROM" Query. (MySQL - Where & Fetch Result Limit)
8. Connect to IP AND Port. (MySQL - FSockOpen)
9. Setting cookie. (PHP Cookies)
9B. Page restriction by cookie. (PHP Cookie REQUIRED)
1. Inserting data to MySQL Table.
PHP:
<?php
// Connecting to the MySQL Server with specific command.
mysql_connect("Connection", "MySQLUser", "MySQLPassword") or die(mysql_error());
// Selecting MySQL Database.
mysql_select_db("DBExample") or die(mysql_error());
// MySQL "Action" the (QueryString)
mysql_query("INSERT INTO Example (ColumnOne, ColumnTwo) VALUES('ColumnOnesValue', 'ColumnTwosValue')") or die(mysql_error());
?>
2. Select from table WHERE.
PHP:
<?php
// Connecting to the MySQL Server with specific command.
mysql_connect("Connection", "MySQLUser", "MySQLPassword") or die(mysql_error());
// Selecting MySQL Database.
mysql_select_db("DBExample") or die(mysql_error());
// MySQL "Action" the (QueryString)
$shortcut = mysql_query("SELECT * FROM Example WHERE ColumnOne='ColumnOnesValue'") or die(mysql_error());
while($row = mysql_fetch_array($shortcut)) {
// Showing results from column one.
echo $row['ColumnOne'];
// New line for another result.
echo '<br />';
// Showing results from column two.
echo $row['ColumnTwo'];
}
?>
3. Updating existing row in table.
PHP:
<?php
// Connecting to the MySQL Server with specific command.
mysql_connect("Connection", "MySQLUser", "MySQLPassword") or die(mysql_error());
// Selecting MySQL Database.
mysql_select_db("DBExample") or die(mysql_error());
// MySQL "Action" the (QueryString)
mysql_query("UPDATE Example SET ColumnTwo='Value' WHERE ColumnOne='AnotherValue'") or die(mysql_error());
?>
4. Deleting specific content from table.
PHP:
<?php
// Connecting to the MySQL Server with specific command.
mysql_connect("Connection", "MySQLUser", "MySQLPassword") or die(mysql_error());
// Selecting MySQL Database.
mysql_select_db("DBExample") or die(mysql_error());
// MySQL "Action" the (QueryString)
mysql_query("DELETE FROM Example WHERE ColumnOne='Value'") or die(mysql_error());
?>
5. What is this "or die(mysql_error());" ?
If your code doesn't work correctly it will report you information about it what's wrong.
6. Creating a MySQL Configuration File.
PHP:
<?php
// Creating shortcuts with values.
$Con = "Connection";
$User = "Username";
$Pass = "Password";
$DB = "Database";
?>
6B. How you can use it?
Everywhere you want to use it you must require the configuration file to receive every "shortcut" to the current document.
PHP:
<?php require("ConfigurationFile.php"); ?>
6C. Using a MySQL Configuration File with MySQL Connection.
PHP:
<?php
// Requiring the configuration file.
// This code must be (in the page) which uses "shortcuts"
require('Path/ConfigurationFile.php');
// Then... connection with it..
mysql_connect($Con, $User, $Pass) or die(mysql_error());
?>
7. Limit for "SELECT * FROM" Query.
PHP:
// Just simply place "LIMIT {Amount}" to query.
mysql_query("SELECT * FROM Example WHERE ColumnOne='ColumnOnesValue' LIMIT 5")
8. Connect to IP AND Port.
PHP:
<?php
// Renaming connection command as "$Server".
$Server = fsockopen("YourIP", "Port", $ErrNo, $ErrStr, 5)
// Connecting to the server using "shortcut" $Server.
if($Server) {
// Show text "Online" if connection success.
echo "Online";
}
else
{
// Show text "Offline" if connection failed.
echo "Offline";
}
?>
9. Setting the cookie.
PHP:
<?php
// Cookies are very simple.
setcookie("CookieName", "ValueOfCookie", time()+86000)
?>
9B. Page need cookie to be shown.
PHP:
<?php
// Checking if cookie = true then...
if(!isset($_COOKIE['CookieName'])) {
die('You need cookie to see this page.');
}
else
{
// Do nothing. In other words continue executing other scripts and page.
}
?>
This is for advanced coders.
The reason why i'm not using if(!$Con) { commands etc functions with my code in this thread is that, because all of those functions confuses new PHP coders.
Never is not too late for learning.
First learn all of these basics and after that... grinding the code.
Last edited: