Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

MySQL

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
NamecheapNamecheap
Watch

abc123ben

Established Member
Impact
2
Hello,

Need help again :|.

OK. Well, I'm reading a PHP & MySQL book, and at the moment on Chapter 4, basically explaining about MySQL queries and that. And it's explaining in good detail. But there's one problem, it doesn't show you "exactly" what to put in the file to make an SQL query:

I go to file manager on my site, and use an SQL query, as follows:

<html>
<head><title>SQL query:</title></head>
<body>
<?php

CREATE DATABASE Test

?>

</body></html>

I have a feeling it isn't how you do an SQL query, well that way anyway. So what's the correct SQL code to do an SQL query please?

Sorry, very new to this :|.
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
abc123ben said:
Hello,

Need help again :|.

OK. Well, I'm reading a PHP & MySQL book, and at the moment on Chapter 4, basically explaining about MySQL queries and that. And it's explaining in good detail. But there's one problem, it doesn't show you "exactly" what to put in the file to make an SQL query:

I go to file manager on my site, and use an SQL query, as follows:

<html>
<head><title>SQL query:</title></head>
<body>
<?php

CREATE DATABASE Test

?>

</body></html>

I have a feeling it isn't how you do an SQL query, well that way anyway. So what's the correct SQL code to do an SQL query please?

Sorry, very new to this :|.
First of all, you need a database connection, here is the code to conenct to a database, and execute a query:

PHP:
<?php
mysql_connect('server_name', 'username', 'password')or die(mysql_error());
mysql_select_db('database_name')or die(mysql_error());
mysql_query('query here')or die(mysql_error());
mysql_close();
?>
 
0
Close
Here it is.

PHP:
<?php
$host = "localhost"; //Because in most cases it is localhost
$user = "root"; //If you are doing this on your Home PC.
$pass = ""; //Not needed if connecting as root and you havent set it. If you have set it then use that password here.

$link = mysql_connect( $host, $user, $pass );
if (! $link )
	die("Couldn't connect to MYSQL");

$mysql_query("CREATE DATABASE Test"); //This creates the database.

mysql_close($link); //Closing the connection. If you want to do more process then don't close it put this at the end of the file.
?>

Update: Mikor beat me to it.
 
0
Close
Thanks :). But I get this error:


Fatal error: Call to undefined function: () in /home/bensgfx/public_html/query.php on line

:s
 
0
Close
put the code of the script here. :)

What have you written in query.php?
 
0
Close
PHP:
<?php
$host = "localhost"; //Because in most cases it is localhost
$user = "bensgfx"; //If you are doing this on your Home PC.
$pass = ""; //Not needed if connecting as root and you havent set it. If you have set it then use that password here.

$link = mysql_connect( $host, $user, $pass );
if (! $link )
    die("Couldn't connect to MYSQL");

$mysql_query("CREATE DATABASE MemberTest"); //This creates the database.

mysql_close($link); //Closing the connection. If you want to do more process then don't close it put this at the end of the file.
?>

I did use a password, but I'm not posting it. Any help appreciated.
 
0
Close
PHP:
<?php
$host = "localhost";
$user = "bensgfx";
$pass = "";
$link = mysql_connect( $host, $user, $pass );
$r = $mysql_query("CREATE DATABASE MemberTest");
?>
Okay to make it less confusing try the above one with your password.
 
0
Close
Try using 'root' as your username, too. I don't know why MySQL would default to your PC username when running on a 'home PC'.
 
0
Close
The problem is you are using $mysql_query. Change that to just mysql_query (no $).
 
0
Close
Dan said:
The problem is you are using $mysql_query. Change that to just mysql_query (no $).
What he said lol.

Ben, do you know if you have phpMyAdmin? (This usually comes with CPanel, if you have CPanel).
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back