473,395 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Connect to the mysql already?

Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista
Jul 17 '05 #1
3 3088
Tom
Not sure why you're:
* passing variables through GET when you're declaring them within your
script
* making and closing two connections to create one table

Unless you're passing variables through a form or a url, why not just access
the variables directly?

Therefore:
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect to
the database because: ' . mysql_error() );

if ($linkID) {
echo "The connection to the server was made successfully<br />";
}

$DBName="Krista";
$TableName = "Employee";

# create a database if one doesn't exist
mysql_create_db($DBName);
#select the database you just created
mysql_select_db($DBName);

#design your query
$resultID = "CREATE TABLE Employee(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

#run the query
$table = mysql_query($resultID) or die("Create table Error: ". mysql_error()
);

#if table was created, echo a message to the screen
if ($resultID) {
echo "The table $TableName was successfully created";
}

mysql_close($linkID);
?>
</body>
</html>

"Krista" <yw*****@hotmail.com> wrote in message
news:eb**************************@posting.google.c om...
Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista

Jul 17 '05 #2
Tom
Whoa, I was a little too quick on the submit key. The amended code should
read as follows:

$resultID = "CREATE TABLE $TableName(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

$table = mysql_query($resultID) or die("Create table Error: ". mysql_error()
);
if ($table) {
echo "The table $TableName was successfully created";
}



"Tom" <ly*****@nospamhotmail.com> wrote in message
news:59iEb.4622$Fg.4394@lakeread01...
Not sure why you're:
* passing variables through GET when you're declaring them within your
script
* making and closing two connections to create one table

Unless you're passing variables through a form or a url, why not just access the variables directly?

Therefore:
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect to
the database because: ' . mysql_error() );

if ($linkID) {
echo "The connection to the server was made successfully<br />";
}

$DBName="Krista";
$TableName = "Employee";

# create a database if one doesn't exist
mysql_create_db($DBName);
#select the database you just created
mysql_select_db($DBName);

#design your query
$resultID = "CREATE TABLE Employee(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

#run the query
$table = mysql_query($resultID) or die("Create table Error: ". mysql_error() );

#if table was created, echo a message to the screen
if ($resultID) {
echo "The table $TableName was successfully created";
}

mysql_close($linkID);
?>
</body>
</html>

"Krista" <yw*****@hotmail.com> wrote in message
news:eb**************************@posting.google.c om...
Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista


Jul 17 '05 #3
"Tom" <ly*****@nospamhotmail.com> wrote in message news:<59iEb.4622$Fg.4394@lakeread01>...
Not sure why you're:
* passing variables through GET when you're declaring them within your
script
* making and closing two connections to create one table Unless you're passing variables through a form or a url, why not just access
the variables directly?
You are right, I want to access the variables directly. However, when
i work as ur code in the following, I cannot display server was made
successfully.
If i do ($_GET['linkID']), i can show the successful message. is it my
config has problem, so i can access the varible directly? But the
global_register is on already. I dont know what is the problem

if ($linkID) {
echo "The connection to the server was made successfully<br />";

Therefore:
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect to
the database because: ' . mysql_error() );

if ($linkID) {
echo "The connection to the server was made successfully<br />";
}

$DBName="Krista";
$TableName = "Employee";

# create a database if one doesn't exist
mysql_create_db($DBName);
#select the database you just created
mysql_select_db($DBName);

#design your query
$resultID = "CREATE TABLE Employee(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

#run the query
$table = mysql_query($resultID) or die("Create table Error: ". mysql_error()
);

#if table was created, echo a message to the screen
if ($resultID) {
echo "The table $TableName was successfully created";
}

mysql_close($linkID);
?>
</body>
</html>

When i try your code as above, I still cannot get the result. The IE
seems keeping load the php file.Cannot get it.
"Krista" <yw*****@hotmail.com> wrote in message
news:eb**************************@posting.google.c om...
Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Mr Dygi | last post by:
Hi, PHP 4.3.4 installed manually from package *.zip and Apache 2. I have a problem with this simple code: <?php $link = mysql_connect("127.0.0.1","","") or die("Could not connect: " ....
7
by: atlasyeo | last post by:
Hi, my first time posting on a newsgroup. anyway, let's cut to the chase. I'm trying to migrate mysql database form one server to another server. So I copied the data from /var/lib/mysql to the...
0
by: Mark Adams | last post by:
I really need some help with this. MySQL will not start on boot despite everything I've done to make sure that it is set to do so. When I start it as root from a terminal with...
4
by: Denis Labon | last post by:
I can't connect to mysql server using the mysql-connector-java-3.0.11. I was able to run the same program when I was running Suse 9.0 but since I install Suse 9.1, I can't connect. The error...
1
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0...
5
by: Shelly | last post by:
(also posted to alt.php.sql and comp.databases.mysql) This is an old problem. I extensively researched the postings on the internet and have found no solution. So, perhaps someone here can...
3
by: pc | last post by:
hi everyone, I am trying to connect to a new mysql installation. I have given root permission to connect to all databases from anywhere; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY...
6
by: markodilore | last post by:
Hey Guys, you helped me once when I tryied to create a database : "Access denied for user ''@'localhost' ". On my Mac OS 10.4, I had no problem creating database and modifying it from the terminal....
2
by: swarajtnj | last post by:
Hi Friends, I am using MySql 5.0. With the Front end as ASP.NET 2.0. I am working a small concern. my company local server to connect the MySql is perfectly working. But when i Connect to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.