Showing posts with label Mysql mysql_error. Show all posts
Showing posts with label Mysql mysql_error. Show all posts

Friday, 5 June 2015

Mysql: Creating a table in a MySQL database

<?php
//connect to your MySQL server using your servername , username
//and password
$conn = mysql_connect("localhost" , "username" , "password");
//if you cannot connect display an error message and exit
if ($conn == false)
{
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}
//create a table called contact , this will contain 2 fields .
//fullname to store a name and email to store an email address
$query = "create table contact" .
"(fullname varchar(255), email varchar(255))";
//store this in $result variable
$result = mysql_db_query ("mydb", $query);
//if successful display this message
if ($result)
echo "Table 'mydb' was successfully created!";
//if unsuuccessful display the error message
else
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_close ();
?>

Mysql: Create a database

<?php
$db = "newdb";
//connect to server with username and password
$connection = @mysql_connect ("localhost","root", "") or die (mysql_error());
//connect to database
$result = @mysql_create_db($db, $connection) or die(mysql_error());
if ($result) {
echo"<P>Database has been created!</P>";
}
?>

Mysql: Creating a table in a MySQL

<?php

//connect to your MySQL server using your servername , username

//and password

$conn = mysql_connect("localhost" , "username" , "password");

//if you cannot connect display an error message and exit

if ($conn == false){
echo mysql_errno().": ".mysql_error()."<BR>";
exit;
}

//create a table called contact , this will contain 2 fields .

//fullname to store a name and email to store an email address

$query = "create table contact" . "(fullname varchar(255), email varchar(255))";

//store this in $result variable

$result = mysql_db_query ("mydb", $query);

//if successful display this message

if ($result)

echo "Table 'mydb' was successfully created!";

//if unsuuccessful display the error message

else

echo mysql_errno().": ".mysql_error()."<BR>";

mysql_close ();

?>

Mysql: Display mysql server information

<?php
//enter you own username and password below
mysql_connect("localhost", "", "") or die("Could not connect: " . mysql_error());
//display server version
printf ("MySQL server version: %s\n", mysql_get_server_info());
?>