1. Access MySQL
2. Creating MySQL database
3. Creating MySQL table
4. Insert Query in MySQL
5. Selecting query in MySQL
6. Using mysql_fetch_array()
7. Using DATE_FORMAT in MySQL
8. Using UPDATE in MySQL
How to Change existing rows in MySQL using UPDATE with the help of PHP??
<?
mysql_connect(‘localhost’);
mysql_select_db(‘foo’);
$result = mysql_query(
"update users set email = ‘babycarl@lerdorf.com’
where id = ‘carl’");
if($result) {
echo mysql_affected_rows();
} else {
echo mysql_error();
}
?>
Also filed in
|
|
What is DATE_FORMAT ?? How to use DATE_FORMAT in MySQL using PHP???
<?
mysql_connect(‘localhost’);
mysql_select_db(‘computereducationworld’);
$result = mysql_query(
"select id, email,
date_format(ts,’W M D, Y %r’) as d
from users order by ts");
if($result) {
while($row = mysql_fetch_assoc($result)) {
echo "$row[id] - $row[email] - $row[d]
\n";
}
} else {
echo mysql_error();
}
?>
Also filed in
|
|
how to Select data from database table using mysql_fetch_array() with PHP ?? answer goes here:
<?
$result = mysql_query("select * from users order by id");
if(!$result) echo mysql_error();
else {
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "$row[id] - $row[Password] - $row[Name] -
$row[email] - $row[ts]
\n";
}
}
?>
Also filed in
|
|
Selecting query in MySQL using PHP
<?
mysql_connect(‘localhost’);
mysql_select_db(‘foo’);
$result = mysql_query("select * from users");
if(!$result) echo mysql_error();
else {
while($row = mysql_fetch_row($result)) {
echo "$row[0] - $row[1] - $row[2] - $row[3] - $row[4]
\n";
}
}
?>
Also filed in
|
|
Inserting query in MySQL
<?php
function add_user($id, $pass, $name, $email) {
$result=mysql_query("insert into users values
(’$id’,ENCRYPT(’$pass’),’$name’,’$email’,NULL)");
if($result) {
echo "Row inserted
";
} else {
echo mysql_error()."
";
}
}
?>
Also filed in
|
|
how to create a table using mySQL in PHP?? Answer goes here:
<?
mysql_select_db(’foo’);
$result = mysql_query(”CREATE TABLE users (
id varchar(16) binary NOT NULL default ”,
Password varchar(16) NOT NULL default ”,
Name varchar(64) default NULL,
email varchar(64) default NULL,
ts timestamp(14) NOT NULL,
PRIMARY KEY (id)
)”);
if($result) {
echo “Table created”;
} else {
echo mysql_error();
}
?>
Also filed in
|
|
Creating a MySQL database using PHP:
<?
mysql_connect(‘localhost’);
if(mysql_query("CREATE DATABASE foo")) {
echo "Database foo created";
} else {
echo mysql_error();
}
?>
Also filed in
|
|
Accessing MySQL with PHP
<?
mysql_connect(’db.domain.com:33306′,’rasmus’,‘foobar’);
mysql_connect(’localhost:/tmp/mysql.sock’);
mysql_connect(’localhost’,’rasmus’,‘foobar’,
true,MYSQL_CLIENT_SSL|MYSQL_CLIENT_COMPRESS);
?>
Also filed in
|
|