MySQL Basic Functions - php Form

Author Topic: MySQL Basic Functions  (Read 2744 times)

Offline alex

  • Global Moderator
  • *****
  • Posts: 77
  • Karma: +19/-0
    • View Profile
MySQL Basic Functions
« on: January 13, 2009, 09:03:47 AM »


Create Database Connection
Code: [Select]
<?php 
$dbhost 
'localhost';
$dbusername 'root';
$dbpassword 'mypassword';
$dbname 'mydbname';
$conn=mysql_connect($dbhost$dbusername$dbpassword);
if(!
$conn) :
   die(
'Could not connect: ' mysql_error());
endif;
$db=mysql_select_db($dbname$conn);
if(!
$db) :
   die (
'Can\'t connect to database : ' mysql_error());
endif;
?>
Select Database
Code: [Select]
<?php 
$result 
mysql_query("SELECT text FROM textbase"
or die(
mysql_error()); 
while(
$link=mysql_fetch_array($result))
{
echo 
$link[text];
}
?>

Delete From Database
Code: [Select]
<?php
$result 
mysql_query("DELETE FROM textbase WHERE textid = 4 ")
or die(
mysql_error());
?>

Update Database
Code: [Select]
<?php
$result 
mysql_query("UPDATE textbase SET textno='1' WHERE textno='0' "
or die(
mysql_error());
?>

« Last Edit: January 13, 2009, 09:11:44 AM by alex »

Offline kelvin

  • Supporter
  • **
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Truncate Mysql Database
« Reply #1 on: January 15, 2010, 05:45:34 AM »
Truncate MySQL Database

Code: [Select]
<?php
include('config.php');
mysql_query('TRUNCATE TABLE textbase');
?>