Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

no database selected

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

no database selected

Postby juliet18 » Wed Jun 04, 2014 5:39 pm

i have a database directory.sql that contain many tables. however when i run my page, I got no database selected. Can anybody knows what happened? some of my database code is shown below. :help:
Code: Select all
-- phpMyAdmin SQL Dump
-- version 3.5.2.2
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jun 04, 2014 at 04:41 PM
-- Server version: 5.5.27
-- PHP Version: 5.4.7

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `directory`
--

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

--
--Table structure for table `bahagian`

--
CREATE TABLE IF NOT EXISTS `bahagian` (
  `kod_bahagian` varchar(10) DEFAULT NULL,
  `nama_bahagian` varchar(100) DEFAULT NULL,
  `status_bahagian` varchar(10) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `bahagian`
--

INSERT INTO `bahagian` (`kod_bahagian`, `nama_bahagian`, `status_bahagian`) VALUES
('01', 'Bahagian Khidmat Pengurusan Pentadbiran Am', 'n'),
('02', 'Bahagian Dasar Saraan, Wang Awam dan Khidmat Pengurusan', 'n'),
('03', 'Bahagian Pentadbiran dan Kewangan', 'n'),
('04', 'Bahagian Pejabat Setiausaha Bahagian Kanan(Pengurusan)', 'n'),
('05', 'Bahagian Pentadbiran dan Keselamatan', 'n'),
('06', 'Bahagian Khidmat Pengurusan', 'n'),
('07', 'Bahagian Pejabat Setiausaha Kanan Khidmat Pengurusan', 'n'),
('08', 'Bahagian Khidmat Pengurusan dan Aset', 'n'),
('09', 'Bahagian Pentadbiran Am', 'n'),
('10', 'Bahagian Khidmat Pengurusan dan Kewangan', 'n'),
('11', 'Tidak Berkenaan', 'n');

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

--
-- Table structure for table `image`
--

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(64) CHARACTER SET armscii8 COLLATE armscii8_bin DEFAULT NULL,
  `name` varchar(64) CHARACTER SET armscii8 COLLATE armscii8_bin DEFAULT NULL,
  `alt` text,
  `img` blob,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `image`
.........................
juliet18
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Jun 02, 2014 11:36 pm

Re: no database selected

Postby peterachutha » Fri Jun 06, 2014 3:55 pm

My guess is that you may have forgotten to connect to your database. You would probably need to add something like the code below before you create tables.


$host = "localhost";
$user = "myusername";
$pass = "mypassword";

$myconn = mysql_connect($host, $user, $pass);

if (!$myconn) {
echo "Could not connect to server\n";

} else {
echo "Connection established\n";

mysql_select_db( 'myusername' );

CREATE TABLE IF NOT EXISTS `bahagian` ( ....
.
.
.
}

I have dropped code such as "ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2" as it was complicating my programming. You can try without it and then add them back later.

Do take a look at the php manual at: http://www.php.net/manual/en/function.m ... ect-db.php as this will be very helpful.
peterachutha
New php-forum User
New php-forum User
 
Posts: 10
Joined: Sat May 31, 2014 10:35 pm

Re: no database selected

Postby peterachutha » Sat Jun 07, 2014 10:20 am

You dengan kerajaan Malaysia? (Are you with the Malaysian Government?) Sebab you punya code, tengok macham dari Bank negara atau lain pentadbiran. (Because your code looks like form Bank Negara (Central Bank) of similar administration.
peterachutha
New php-forum User
New php-forum User
 
Posts: 10
Joined: Sat May 31, 2014 10:35 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.