Some MySQL For The Brain

Looking for a few, quick PHP+MySQL tips? You found some.

List all tables in the pre-set database:

SHOW TABLES;

Always, always, always use an auto-incrementing unique ID:

CREATE TABLE table_name (
id INT NOT NULL AUTO_INCREMENT,
table_field1 varchar(250) NOT NULL default ”,
PRIMARY KEY (id)
);

Adding to an auto-incrementing table:

@mysql_query(”insert into table_name values(NULL,’My Field’)”);

There’s actually three different PHP API’s which you can use:

  • The C Language API:
    Link your app. with the libmysqlclient.so library that is usually installed automatically when you compile MySQL from source. (We will actually be creating several tutorials about the C PHP API soon here.)
  • The Perl API:
    Using the Database Interface (DBI) and a Database Driver (DBD) you can use this API.
  • The PHP API:
    The most popular MySQL API is the PHP API. It is pre-packaged with PHP versions below 5. (Of course, we’ll be creating several tutorials very soon about the PHP API, and it’s new brother, MySQLi.)

Need to take a quick dump? :)

mysqldump –user=ben –password=mypassword \ mydb > dumpfile.sql

That’s all for now folks! We’ll be writing a lot here in the very near future. Stay tuned!

Leave a Reply

You must be logged in to post a comment.