* Gordon Stewart
> I've been following the website of :-
>
> http://www.wdvl.com/Authoring/DB/SQL/Build/
>
> And its the best ive seen - so far...
>
> Im up to this page :-
>
> http://www.wdvl.com/Authoring/DB/SQL/Build/build4-5.html
>
> & now i'm stuck - I need to know 2-3 more things that i can do WITHIN /
> USING Perl..
>
> My coder (see below)...
>
>  From the build4-5 web-page above, I'll assume that
>   $result = @mysql_query("show databases"); would be the correct code to
> SHOW the databases available..

That is correct.

> However its not going & the website doesnt have the 2 commands
> that i want to do..

oki... what 2 commands, and what happens? Do you get an error message?

> Can someone advise me the commands to :-
>
> 1) View/List Databases / Tables

SHOW DATABASES;

and

SHOW TABLES;

<URL: http://www.mysql.com/doc/S/H/SHOW_DATABASE_INFO.html >

> 1A) Add / create a Database/Table (I'll assume you use the
> @mysql_query in some way.

CREATE DATABASE MyBrandNewDatabase;

USE MyBrandNewDatabase;

CREATE TABLE MyBrandNewTable (
  MyIdField int primary key,
  MyTextField varchar(30)
);

<URL: http://www.mysql.com/doc/C/R/CREATE_TABLE.html >

And yes, in PHP you use mysql_query() to execute the sql statements on the
mysql server you have connected with mysql_connect(). If the query returns a
result, you use the mysql_fetch_*()-functions or mysql_result() to get the
result.

To make away with one common mistake: the mysql_query() function accepts
_one_ single sql statement, without a semicolon at the end. You can always
execute multiple statements, but they have to be in separate mysql_query()
calls. On this mailinglist you will frequently see sql with semicolons (like
my code above.) This is because the semicolon is _required_ when you execute
the statements in the mysql client console. (Actually, the semicolon can be
replaced by \g or \G, but this is not so common.) Just ignore the semicolons
when you but the statements in your mysql_query() function call.

> 2) Ive figured out what these mean - But are there others _ that do other
> things ? - A list of them ?
>
> @mysql_select_db
> @mysql_query

The PHP site has a special page for mysql:

<URL: http://www.php.net/manual/en/ref.mysql.php >

There are quite a lot of functions... :)

> mysql_fetch_array << Can someone explain why theres no @ sign - &
> a website that explains this further...

The @ operator is used to ignore any errors the function generates. It can
be used with any function, but it is usually better to catch the error and
do some apropriate error handling. Read more about @ here:

<URL: http://www.php.net/manual/en/language.operators.errorcontrol.php >

>     // Request the text of all the jokes
>    $result = @mysql_query("show databases");
>    if (!$result) {
>      echo("<p>Error performing query: " . mysql_error() . "</p>");
>      exit();
>    }
>    // Display the text of each joke in a paragraph
>    while ( $row = mysql_fetch_array($result) ) {
>      echo("<p>" . $row["JokeText"] . "</p>");
>    }

There is no column called "JokeText" in the output of the "show databases"
query... that is why this does not work. The name of the column returned is
"Database". Change your script to $row["Database"], and it should work.

The name of the column of tables returned by "show tables" is named
"Tables_in_" . $db_name, like in "Tables_in_test" or "Tables_in_mydb". You
can check this by running your query ("show databases;" or "show tables;")
in the mysql client console.

--
Roger


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to