Support Forums
Help: SQL without phpmyadmin? - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Database Programming (https://www.supportforums.net/forumdisplay.php?fid=28)
+---- Thread: Help: SQL without phpmyadmin? (/showthread.php?tid=3895)



Help: SQL without phpmyadmin? - nevets04 - 12-24-2009

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.


RE: Help: SQL without phpmyadmin? - Gaijin - 12-24-2009

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);

?>



RE: Help: SQL without phpmyadmin? - nevets04 - 12-24-2009

(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()


RE: Help: SQL without phpmyadmin? - Gaijin - 12-24-2009

(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();


RE: Help: SQL without phpmyadmin? - nevets04 - 12-24-2009

Can you make it write the names of each row on top like:

| id | name | telephone | birthday |


RE: Help: SQL without phpmyadmin? - Gaijin - 12-24-2009

(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 />"




RE: Help: SQL without phpmyadmin? - nevets04 - 12-24-2009

(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


RE: Help: SQL without phpmyadmin? - wat - 12-30-2009

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.