Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help: SQL without phpmyadmin?
#1
I've been learning SQL through phpmyadmin, but I also want to see what it's like without phpmyadmin. However, I'm having some problems.
I have
Code:
-- phpMyAdmin SQL Dump
-- version 3.1.2deb1ubuntu0.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 24, 2009 at 01:58 AM
-- Server version: 5.0.75
-- PHP Version: 5.2.6-3ubuntu4.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `mydomain`
--

-- --------------------------------------------------------

--
-- Table structure for table `people`
--

CREATE TABLE IF NOT EXISTS `people` (
  `id` int(6) NOT NULL,
  `name` char(100) NOT NULL,
  `telephone` char(50) NOT NULL,
  `birthday` char(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `people`
--

INSERT INTO `people` (`id`, `name`, `telephone`, `birthday`) VALUES
(100100, 'ross', '222 222 222', '3 january'),
(200200, 'John', '999 999 999', '19 may'),
(300300, 'jane', '888 888 888', '19 july');

saved into Test.sql

I want to see my chart or some sort of result in my browser, how do I do this. I've already tried putting it in /var/www/. However, that didn't work, it only displayed Test.sql in plain text.
Reply
#2
You'll need to write an PHP code for that, first you'll need to connect to the database and then fetch resuls... and show them.

PHP Code:
<?php

$db 
= array(
    
'host' => 'localhost'// your host
    
'user' => 'root',   //username
    
'pass' => '',       //password
    
'base' => 'test' //database name not table
);


// connecting to the database
if($connect mysql_connect($db['host'], $db['user'], $db['pass'])) {
    
// selecting the database
    
if(!$sel mysql_select_db($db['base'])) {
        die(
"Connection failed..<br />".mysql_error());
    }
}

//sql query string
$sql "SELECT * FROM `people`";
//execute sql query
if(!$query mysql_query($sql)) {
    die(
mysql_error()); // die and show error
}

//if mysql_num_rows returns 0 there isn't anything in the table
if(mysql_num_rows($query) <= 0) {
    die(
"There are no entries in the database");
}

//fetch result from the query
while($rows mysql_fetch_array($query)) {
    echo 
$rows['id']." : ".$rows['name']." : ".$rows['telephone']." : ".$rows['birthday']."<br />";
}


//close connection
mysql_cl($connect);

?>
Reply
#3
(12-24-2009, 07:46 AM)Master of The Universe Wrote: You'll need to write an PHP code for that, first you'll need to connect to the database and then fetch resuls... and show them.

PHP Code:
<?php

$db 
= array(
    
'host' => 'localhost'// your host
    
'user' => 'root',   //username
    
'pass' => '',       //password
    
'base' => 'test' //database name not table
);


// connecting to the database
if($connect mysql_connect($db['host'], $db['user'], $db['pass'])) {
    
// selecting the database
    
if(!$sel mysql_select_db($db['base'])) {
        die(
"Connection failed..<br />".mysql_error());
    }
}

//sql query string
$sql "SELECT * FROM `people`";
//execute sql query
if(!$query mysql_query($sql)) {
    die(
mysql_error()); // die and show error
}

//if mysql_num_rows returns 0 there isn't anything in the table
if(mysql_num_rows($query) <= 0) {
    die(
"There are no entries in the database");
}

//fetch result from the query
while($rows mysql_fetch_array($query)) {
    echo 
$rows['id']." : ".$rows['name']." : ".$rows['telephone']." : ".$rows['birthday']."<br />";
}


//close connection
mysql_cl($connect);

?>

Thanks, this worked great. Only thing is I think mysql_cl() should be mysql_close()
Reply
#4
(12-24-2009, 12:28 PM)nevets04 Wrote: Thanks, this worked great. Only thing is I think mysql_cl() should be mysql_close()

Yeah you're right, sorry about that.
It is mysql_close();
Reply
#5
Can you make it write the names of each row on top like:

| id | name | telephone | birthday |
Reply
#6
(12-24-2009, 12:38 PM)nevets04 Wrote: Can you make it write the names of each row on top like:

| id | name | telephone | birthday |

Just put this right before the while function.

PHP Code:
echo "id | name | telephone | birthday <br />"

Reply
#7
(12-24-2009, 12:44 PM)Master of The Universe Wrote: Just put this right before the while function.

PHP Code:
echo "id | name | telephone | birthday <br />"


K, thanks
Reply
#8
nevets, you should also look into the mysql command line. It displays your tables in the fashion you described and it allows you to enter sql queries one-by-one.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to open a 750 mb database,sql file? etc 17 7,465 08-21-2011, 03:57 AM
Last Post: AceInfinity
  Why not use this to help prevent SQL injection? ★Cooldude★ 29 13,797 06-30-2011, 07:06 AM
Last Post: ControL1
  Help. Having trouble logging into phpmyadmin. nevets04 4 2,036 12-24-2009, 12:08 AM
Last Post: nevets04
  SQL Interacting with Form Cppsean 3 1,648 10-19-2009, 12:21 PM
Last Post: Omniscient

Forum Jump:


Users browsing this thread: 4 Guest(s)